Docs Menu
Docs Home
/
MongoDB Manual
/ / /

db.dropUser()

On this page

  • Definition
  • Behavior
  • Required Access
  • Example
db.dropUser(username, writeConcern)

Removes the user from the current database.

Important

mongosh Method

This page documents a mongosh method. This is not the documentation for database commands or language-specific drivers, such as Node.js.

For the database command, see the dropUser command.

For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.

For the legacy mongo shell documentation, refer to the documentation for the corresponding MongoDB Server release:

mongo shell v4.4

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

Parameter
Type
Description
username
string
The name of the user to remove from the database.
writeConcern
document

Optional. The level of write concern for the operation. See Write Concern Specification.

The db.dropUser() method wraps the dropUser command.

Before dropping a user who has the userAdminAnyDatabase role, ensure you have at least another user with user administration privileges.

If run on a replica set, db.dropUser() is executed using "majority" write concern by default.

You must have the dropUser action on a database to drop a user from that database.

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

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

Back

db.createUser()