[英]how can I drop user from "system.users" using mongodb and PHP?
I need a small help.我需要一点帮助。
I can not delete "System.User" user from MongoDB database.我无法从 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;
}
Below code delete just database and particular database user only not "System.User"下面的代码只删除数据库和特定的数据库用户,而不是“System.User”
$command = array
(
"dropUser" => $mydb
);
$db = $m->selectDB( $mydb );
$db->command( $command );
$db = $m->dropDB( $mydb );
The following db.dropUser() operation drops the reportUser1 user on the products database.以下 db.dropUser() 操作删除产品数据库上的 reportUser1 用户。
use products
db.dropUser("reportUser1", {w: "majority", wtimeout: 5000})
reference : db.dropUser参考: db.dropUser
Try following code for php试试下面的php代码
$users = $conn->$db_name->selectCollection('system.users')->delete();
I need a small help.我需要一点帮助。
I can not delete "System.User" user from MongoDB database.我无法从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;
}
Below code delete just database and particular database user only not "System.User"下面的代码仅删除数据库,而仅删除特定的数据库用户,而不删除“ System.User”
$command = array
(
"dropUser" => $mydb
);
$db = $m->selectDB( $mydb );
$db->command( $command );
$db = $m->dropDB( $mydb );
If I understand it right, you are looking for deleting one collection in mongodb database using PHP.如果我理解正确,您正在寻找使用 PHP 在 mongodb 数据库中删除一个集合。 If that is the case then, you can use the below method to drop a collection from mongodb.如果是这种情况,您可以使用以下方法从 mongodb 中删除集合。
$collection = $mongo->my_db->System.User; $collection = $mongo->my_db->System.User;
$response = $collection->drop(); $response = $collection->drop();
You can follow the below link to get more details about the same - https://www.php.net/manual/en/mongocollection.drop.php您可以按照以下链接获取更多详细信息 - https://www.php.net/manual/en/mongocollection.drop.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.