db.dropAllUsers()
On this page本页内容
Definition定义
db.dropAllUsers(writeConcern)-
Removes all users from the current database.从当前数据库中删除所有用户。Importantmongosh Method
This page documents a
mongoshmethod. This is not the documentation for database commands or language-specific drivers, such as Node.js.For the database command, see the
dropAllUsersFromDatabasecommand.For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.
For the legacy
mongoshell documentation, refer to the documentation for the corresponding MongoDB Server release:WarningThedb.dropAllUsers()method removes all users from the database.db.dropAllUsers()方法从数据库中删除所有用户。Thedb.dropAllUsers()method takes the following arguments:db.dropAllUsers()方法采用以下参数:Field字段Type类型Description描述writeConcerndocument Optional.可选的。The level of write concern for the operation.操作的写入关注级别。See Write Concern Specification.请参阅写入关注规范。Thedb.dropAllUsers()method wraps thedropAllUsersFromDatabasecommand.db.dropAllUsers()方法包装dropAllUsersFromDatabase命令。
Behavior行为
Replica set副本集
If run on a replica set, 如果在副本集上运行,db.dropAllUsers() is executed using "majority" write concern by default.db.dropAllUsers()默认情况下使用"majority"写入关注执行。
Required Access所需访问权限
You must have the 必须对数据库执行dropUser action on a database to drop a user from that database.dropUser操作才能从该数据库中删除用户。
Example实例
The following 以下db.dropAllUsers() operation drops every user from the products database.db.dropAllUsers()操作将从products数据库中删除每个用户。
use products
db.dropAllUsers( {w: "majority", wtimeout: 5000} )
The 结果文档中的n field in the results document shows the number of users removed:n字段显示删除的用户数:
{ "n" : 12, "ok" : 1 }