db.dropAllRoles()

On this page本页内容

Definition定义

db.dropAllRoles(writeConcern)

Deletes all user-defined roles on the database where you run the method.删除运行该方法的数据库上所有用户定义的角色。

Warning

The dropAllRoles method removes all user-defined roles from the database.dropAllRoles方法从数据库中删除所有用户定义的角色。

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

Field字段Type类型Description描述
writeConcern document Optional.可选。The level of write concern for the removal operation. 删除操作的写入关注级别。The writeConcern document takes the same fields as the getLastError command.writeConcern文档采用与getLastError命令相同的字段。
Returns:返回:The number of user-defined roles dropped.删除的用户定义角色数。

The db.dropAllRoles() method wraps the dropAllRolesFromDatabase command.db.dropAllRoles()方法包装dropAllRolesFromDatabase命令。

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数据库中删除所有用户定义的角色,并使用了一个写入关注点

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

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

4