db.dropUser()

Definition

  • db.dropUser(username, writeConcern)
  • Removes the user from the current database.

The db.dropUser() method takes the following arguments:

ParameterTypeDescriptionusernamestringThe name of the user to remove from the database.writeConcerndocumentOptional. The level of write concern for theremoval operation. The writeConcern document takes the samefields as the getLastError command.

The db.dropUser() method wraps the dropUsercommand.

Before dropping a user who has the userAdminAnyDatabaserole, ensure you have at least another user with user administrationprivileges.

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 dropUseraction on a database to drop a user from that database.

Example

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

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