dropAllUsersFromDatabase (original) (raw)

dropAllUsersFromDatabase

Removes all users from the database on which you run the command.

Tip

In mongosh, this command can also be run through the db.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.

This command is available in deployments hosted in the following environments:

Important

This command is not supported in M0, M2, M5, and Flex clusters. For more information, see Unsupported Commands.

The command has the following syntax:


db.runCommand(

   {

     dropAllUsersFromDatabase: 1,

     writeConcern: { <write concern> },

     comment: <any>

   }

)

The command takes the following fields:

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

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: