MongoDB: db.dropUser() method
db.dropUser()
The db.dropUser() method is used to removes the user form the current database.
Syntax:
db.dropUser(username, writeConcern)
Parameters:
Name | Description | Required / Optional |
Type |
---|---|---|---|
username | The name of the user to remove from the database. | Required | string |
writeConcern | The level of write concern for the removal operation. The writeConcern document takes the same fields as the getLastError command. | Optional | document |
Before dropping a user who has the userAdminAnyDatabase role, ensure you have at least another user with user administration privileges.
Example: MongoDB: db.dropUser() method
The user mynewuser in the test database.
> db.getUser("mynewuser");
{
"_id" : "test.mynewuser",
"user" : "mynewuser",
"db" : "test",
"roles" : [
{
"role" : "read",
"db" : "assets"
},
{
"role" : "read",
"db" : "orders"
},
{
"role" : "readWrite",
"db" : "test"
}
],
"customData" : {
"employeeId" : "0x3039"
}
}
The following db.dropUser() operation drops the mynewuser user on the test database.
use test
db.dropUser("mynewuser", {w: "majority", wtimeout: 4000})
Output:
> db.dropUser("mynewuser", {w: "majority", wtimeout: 4000}); true
Retrieve the restaurants data from here
Previous:
db.dropAllUsers() method
Next:
db.grantRolesToUser() method
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://www.w3resource.com/mongodb/shell-methods/user-management/db-dropUser.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics