1

I need a small help.

I can not delete "System.User" user from MongoDB database.

/*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"

$command = array
   (
       "dropUser" => $mydb
   );
   $db = $m->selectDB( $mydb );
   $db->command( $command );
   $db = $m->dropDB( $mydb );

enter image description here

HEMAL
  • 420
  • 3
  • 14

2 Answers2

0

The following db.dropUser() operation drops the reportUser1 user on the products database.

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

reference : db.dropUser

Try following code for php

$users = $conn->$db_name->selectCollection('system.users')->delete();
ANIK ISLAM SHOJIB
  • 3,002
  • 1
  • 27
  • 36
  • Thanks for the answer but in PHP how can I drop the user ("system.users"). "db.dropUser" yes this function works only current db users only not "system.users" collection. – HEMAL Jan 02 '20 at 07:05
-2

If I understand it right, you are looking for deleting one collection in mongodb database using PHP. If that is the case then, you can use the below method to drop a collection from mongodb.

$collection = $mongo->my_db->System.User;
$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