db.dropAllUsers()

On this page本页内容

Definition定义

db.dropAllUsers(writeConcern)

Removes all users from the current database.

Warning

The dropAllUsers method removes all users from the database.

The dropAllUsers method takes the following arguments:

Field字段Type类型Description描述
writeConcern document Optional.可选。The level of write concern for the removal operation. The writeConcern document takes the same fields as the getLastError command.

The db.dropAllUsers() method wraps the dropAllUsersFromDatabase 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 dropUser action on a database to drop a user from that database.

Example示例

The following db.dropAllUsers() operation drops every user from the products database.

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

The n field in the results document shows the number of users removed:

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