Docs HomeMongoDB Manual

db.dropRole()

Definition定义

db.dropRole( rolename, writeConcern )

Deletes a user-defined role from the database on which you run the method.从运行该方法的数据库中删除用户定义的角色。

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 dropRole 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.dropRole() method takes the following arguments:db.dropRole()方法采用以下参数:

Parameter参数Type类型Description描述
rolenamestringThe name of the user-defined role to remove from the database.要从数据库中删除的用户定义角色的名称。
writeConcerndocumentOptional.可选的。The level of write concern for the operation. 操作的写入关注级别。See Write Concern Specification. 请参阅写入关注规范

Behavior行为

Authentication身份验证

When a role is dropped on a mongod, previously authenticated users remain logged in to the database but immediately lose the role's privileges.当一个角色被放到mongod上时,以前经过身份验证的用户仍然登录到数据库,但会立即失去该角色的权限。

When a role is dropped on a mongos, previously authenticated users remain logged in to the database but lose the role's privileges when the cache refreshes. 当在mongos上删除角色时,以前经过身份验证的用户仍然登录到数据库,但在缓存刷新时会失去角色的权限。The cache refreshes automatically after the time specified with the userCacheInvalidationIntervalSecs parameter or manually when you run the invalidateUserCache command.在使用userCacheInvalidationIntervalSecs参数指定的时间后,缓存会自动刷新,或者在运行invalidateUserCache命令时手动刷新。

Replica Set复制副本集

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

Required Access所需访问权限

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

Example实例

The following operations remove the readPrices role from the products database:以下操作将从products数据库中删除readPrices角色:

use products
db.dropRole( "readPrices", { w: "majority" } )