简体   繁体   English

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

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

相关问题 如何使用 MongoDB 驱动程序为 php 7 执行 drop()? - How to perform drop() using MongoDB drivers for php 7? PHP/MySQL:在投票系统中,如何防止用户看到他已经投票的个人资料? - PHP/MySQL: In a Voting System, how can I keep a user from seeing a profile he has already voted on? 使用php和html,如何计算从下拉列表中进行选择的次数? - Using php and html, how can I count the number of times a selection is made from a drop down list? 使用javascript或PHP,如何使用下拉列表或文本框中的值。 - Using javascript or PHP how can I use the value from a drop down list or a text box. 如何使用PHP随机但公平地从加权'用户'列表中创建'团队'? - How can I create 'teams' from a list of weighted 'users' randomly but fairly using PHP? 如何使用PHP在图像中添加阴影? - How can I add a drop-shadow to an image using PHP? 如何使用 php 向大量用户发送电子邮件? - how can i send an email to lots of users using php? 如何使用PHP隐藏某些用户的内容? - How can I hide some content from some users with PHP? 如何向最终用户隐藏 php 错误详细信息 - How I can hide php error details from end users 我如何尝试使用PHP驱动程序从MongoDB中的2个或更多集合中获取信息 - How can I try to get information from 2 or more collections in MongoDB using PHP driver
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM