Docs 菜单

db.dropRole()

db.dropRole( rolename, writeConcern )

Deletes a user-defined role from the database on which you run the method.

重要

mongosh 方法

本页面提供 mongosh 方法的相关信息。这不是数据库命令或特定语言驱动程序(例如 Node.js)的相关文档。

有关数据库命令,请参阅 dropRole 命令。

如需了解 MongoDB API 驱动程序,请参阅特定语言的 MongoDB 驱动程序文档。

db.dropRole() 方法接受以下参数:

Parameter
类型
说明

rolename

字符串

The name of the user-defined role to remove from the database.

writeConcern

文档

可选。操作的写关注级别。请参阅写关注规范

此方法可用于以下环境中托管的部署:

When a role is dropped on a mongod, previously authenticated users remain logged in to the database but immediately lose the role's privileges.

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. The cache refreshes automatically after the time specified with the userCacheInvalidationIntervalSecs parameter or manually when you run the invalidateUserCache command.

如果在副本集上运行,则默认情况下使用 "majority" 写关注执行 db.dropRole()

必须对数据库执行dropRole操作才能从该数据库中删除角色。

The following operations remove the readPrices role from the products database:

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