dropAllUsersFromDatabase
Definition
dropAllUsersFromDatabase
Removes all users from the database on which you run the command.
Tip
In
mongosh
, this command can also be run through thedb.dropAllUsers()
helper method.Helper methods are convenient for
mongosh
users, but they may not return the same level of information as database commands. In cases where the convenience is not needed or the additional return fields are required, use the database command.Warning
The
dropAllUsersFromDatabase
removes all users from the database.
Compatibility
This command is available in deployments hosted in the following environments:
MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
Important
This command is not supported in M0, M2, and M5 clusters. For more information, 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
Syntax
The command has the following syntax:
db.runCommand( { dropAllUsersFromDatabase: 1, writeConcern: { <write concern> }, comment: <any> } )
Command Fields
The command takes the following fields:
Field | Type | Description |
---|---|---|
| integer | Specify |
| document | Optional. The level of write concern for the operation. See Write Concern Specification. |
| any | Optional. A user-provided comment to attach to this command. Once set, this comment appears alongside records of this command in the following locations:
A comment can be any valid BSON type (string, integer, object, array, etc). |
Required Access
You must have the dropUser
action on a database to drop a user from that database.
Example
The following sequence of operations in mongosh
drops
every user from the products
database:
use products db.runCommand( { dropAllUsersFromDatabase: 1, writeConcern: { w: "majority" } } )
The n
field in the results document shows the number of users
removed:
{ "n" : 12, "ok" : 1 }