繁体   English   中英

如何使用 mongodb 和 PHP 从“system.users”中删除用户?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM