Definition定义
db.dropAllRoles( writeConcern )Deletes all user-defined roles on the database where you run the method.
Warning
The
db.dropAllRoles()method removes all user-defined roles from the 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.For the database command, see the
dropAllRolesFromDatabasecommand.For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.
The
db.dropAllRoles()method takes the following argument:Field字段Type类型Description描述writeConcerndocument文档Optional.可选。The level of write concern for the operation. See Write Concern Specification.Returns:返回The number of user-defined roles dropped.
Compatibility兼容性
This method is available in deployments hosted in the following environments:
Important
This command is not supported in MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.
- 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.dropAllRoles() is executed using "majority" write concern by default.
Required Access所需访问权限
You must have the dropRole action on a database to drop a role from that database.
Example示例
The following operations drop all user-defined roles from the products database and uses a write concern of majority.
use products
db.dropAllRoles( { w: "majority" } )
The method returns the number of roles dropped:
4