db.dropAllUsers()

Definition

  • db.dropAllUsers(writeConcern)
  • Removes all users from the current database.

Warning

The dropAllUsers method removes all users from thedatabase.

The dropAllUsers method takes the following arguments:

FieldTypeDescriptionwriteConcerndocumentOptional. The level of write concern for theremoval operation. The writeConcern document takes the samefields as the getLastError command.

The db.dropAllUsers() method wraps thedropAllUsersFromDatabase command.

Behavior

Replica set

If run on a replica set, db.dropAllUsers() 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.dropAllUsers() operation drops every user fromthe products database.

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

The n field in the results document shows the number of usersremoved:

  1. { "n" : 12, "ok" : 1 }