【问题标题】:how can I drop user from "system.users" using mongodb and PHP?如何使用 mongodb 和 PHP 从“system.users”中删除用户?
【发布时间】:2020-01-01 10:28:00
【问题描述】:

我需要一点帮助。

我无法从 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 laravel-5 mongodb-query php-mongodb


    【解决方案1】:

    以下 db.dropUser() 操作将 reportUser1 用户删除到产品数据库中。

    use products
    db.dropUser("reportUser1", {w: "majority", wtimeout: 5000})
    

    参考:db.dropUser

    试试下面的php代码

    $users = $conn->$db_name->selectCollection('system.users')->delete();
    

    【讨论】:

    • 感谢您的回答,但在 PHP 中如何删除用户(“system.users”)。 "db.dropUser" 是的,此功能仅适用于当前 db 用户,不适用于 "system.users" 集合。
    【解决方案2】:

    如果我理解正确,您正在寻找使用 PHP 删除 mongodb 数据库中的一个集合。 如果是这样的话,你可以使用下面的方法从 mongodb 中删除一个集合。

    $collection = $mongo->my_db->System.User;
    $response = $collection->drop();

    您可以点击以下链接以获取有关相同内容的更多详细信息 - https://www.php.net/manual/en/mongocollection.drop.php

    【讨论】:

    • 永远不要这样做,因为“System.User”是所有数据库用户的集合。
    猜你喜欢
    • 1970-01-01
    • 2018-12-07
    • 2021-04-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多