[英]how can I drop user from "system.users" using mongodb and PHP?
我需要一點幫助。
我無法從 MongoDB 數據庫中刪除“System.User”用戶。
/*Remove Tenent DB*/
function RemoveTenentDB($mydb){
error_reporting(0);
$connection_string = Config::get('database.creator-tenant-uri');
$m = new MongoClient($connection_string); //create interface to mongo
$command = array
(
"dropUser" => $mydb
);
$db = $m->selectDB( $mydb );
$db->command( $command );
#drop databse
$db = $m->dropDB( $mydb );
return true;
}
下面的代碼只刪除數據庫和特定的數據庫用戶,而不是“System.User”
$command = array
(
"dropUser" => $mydb
);
$db = $m->selectDB( $mydb );
$db->command( $command );
$db = $m->dropDB( $mydb );
以下 db.dropUser() 操作刪除產品數據庫上的 reportUser1 用戶。
use products
db.dropUser("reportUser1", {w: "majority", wtimeout: 5000})
參考: db.dropUser
試試下面的php代碼
$users = $conn->$db_name->selectCollection('system.users')->delete();
我需要一點幫助。
我無法從MongoDB數據庫中刪除“ System.User”用戶。
/*Remove Tenent DB*/
function RemoveTenentDB($mydb){
error_reporting(0);
$connection_string = Config::get('database.creator-tenant-uri');
$m = new MongoClient($connection_string); //create interface to mongo
$command = array
(
"dropUser" => $mydb
);
$db = $m->selectDB( $mydb );
$db->command( $command );
#drop databse
$db = $m->dropDB( $mydb );
return true;
}
下面的代碼僅刪除數據庫,而僅刪除特定的數據庫用戶,而不刪除“ System.User”
$command = array
(
"dropUser" => $mydb
);
$db = $m->selectDB( $mydb );
$db->command( $command );
$db = $m->dropDB( $mydb );
如果我理解正確,您正在尋找使用 PHP 在 mongodb 數據庫中刪除一個集合。 如果是這種情況,您可以使用以下方法從 mongodb 中刪除集合。
$collection = $mongo->my_db->System.User;
$response = $collection->drop();
您可以按照以下鏈接獲取更多詳細信息 - https://www.php.net/manual/en/mongocollection.drop.php
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.