Docs HomeMongoDB Manual

db.dropAllRoles()

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.db.dropAllRoles()方法从数据库中删除所有用户定义的角色。

Important

mongosh Method

This page documents a mongosh method. This is not the documentation for database commands or language-specific drivers, such as Node.js.

For the database command, see the dropAllRolesFromDatabase command.

For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.

For the legacy mongo shell documentation, refer to the documentation for the corresponding MongoDB Server release:

mongo shell v4.4

The db.dropAllRoles() method takes the following argument:db.dropAllRoles()方法采用以下参数:

Field字段Type类型Description描述
writeConcerndocumentOptional.可选的。The level of write concern for the operation. 操作的写入关注级别。See Write Concern Specification. 请参阅写入关注规范
Returns:返回值:The number of user-defined roles dropped.删除的用户定义角色数。

Behavior行为

Replica set副本集

If run on a replica set, db.dropAllRoles() is executed using "majority" write concern by default.如果在副本集上运行,db.dropAllRoles()默认情况下使用"majority"写入关注执行。

Required Access所需访问权限

You must have the dropRole action on a database to drop a role from that database.必须对数据库执行dropRole操作才能从该数据库中删除角色。

Example实例

The following operations drop all user-defined roles from the products database and uses a write concern of majority.以下操作将从products数据库中删除所有用户定义的角色,并使用majority写入关注

use products
db.dropAllRoles( { w: "majority" } )

The method returns the number of roles dropped:该方法返回丢弃的角色数:

4