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
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook