db.dropUser()
Definition
db.dropUser(username, writeConcern)
Removes the user from the current database.
The
db.dropUser()
method takes the following arguments:ParameterTypeDescriptionusername
stringThe name of the user to remove from the database.writeConcern
documentOptional. The level of write concern for the operation. See Write Concern Specification.
The
db.dropUser()
method wraps thedropUser
command.Before dropping a user who has the
userAdminAnyDatabase
role, ensure you have at least another user with user administration privileges.
Compatibility
This method is available in deployments hosted in the following environments:
Important
This command is not supported in MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.
MongoDB Enterprise: The subscription-based, self-managed version of MongoDB
MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB
Behavior
Replica set
If run on a replica set, db.dropUser()
is executed using
"majority"
write concern by default.
Required Access
You must have the dropUser
action on a database to drop a user from that database.
Example
The following db.dropUser()
operation drops the reportUser1
user on the products
database.
use products db.dropUser("reportUser1", {w: "majority", wtimeout: 5000})