Definition定义
db.dropAllUsers(writeConcern)Removes all users from the current database.从当前数据库中删除所有用户。Important
mongosh
Method方法This page documents a本页记录了一种mongoshmethod. This is not the documentation for database commands or language-specific drivers, such as Node.js.mongosh方法。这不是数据库命令或特定语言驱动程序(如Node.js)的文档。For the database command, see the有关数据库命令,请参阅dropAllUsersFromDatabasecommand.dropAllUsersFromDatabase命令。For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.有关MongoDB API驱动程序,请参阅特定语言的MongoDB驱动程序文档。Warning
Thedb.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命令。
Compatibility兼容性
This method is available in deployments hosted in the following environments:此方法在以下环境中托管的部署中可用:
Important
This command is not supported in MongoDB Atlas clusters. MongoDB Atlas集群不支持此命令。For information on Atlas support for all commands, see Unsupported Commands.有关Atlas支持所有命令的信息,请参阅不支持的命令。
- MongoDB Enterprise
: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本 - MongoDB Community
: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本
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 }