Docs HomeMongoDB Manual

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 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.

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描述
dropAllUsersFromDatabaseintegerSpecify 1 to drop all the users from the current database.
writeConcerndocumentOptional.可选的。The level of write concern for the operation. See Write Concern Specification.
commentanyOptional.可选的。
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).
New in version 4.4. 4.4版新增。

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字段显示删除的用户数:

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