w3resource

MongoDB: db.dropAllUsers() method

db.dropAllUsers()

The db.dropAllUsers() method is used to remove all users associated with a database.

Syntax:

db.dropAllUsers(writeConcern)

Removes all users from the current database.

Note

The dropAllUsers method removes all users from the database.

The dropAllUsers method takes the following arguments:

Parameters:

Name Description Required /
Optional
Type
writeConcern The level of write concern for the removal operation. The writeConcern document takes the same fields as the getLastError command. Required document

Example: MongoDB: db.dropAllUsers() method

Assume that there is n user mynewuser1 in the test database.

null
> db.getUser("mynewuser1");
{
        "_id" : "test.mynewuser1",
        "user" : "mynewuser1",
        "db" : "test",
        "roles" : [ ]
}
use test
db.dropAllUsers( {w: "majority", wtimeout: 5000} );

Output:

> db.dropAllUsers( {w: "majority", wtimeout: 5000} );
2

Retrieve the restaurants data from here

Previous: db.changeUserPassword() method
Next: db.dropUser() method



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/mongodb/shell-methods/user-management/db-dropAllUsers.php