dropRole
定义
dropRole
Deletes a user-defined role from the database on which you run the command.
提示
在
mongosh
中,该命令也可通过db.dropRole()
辅助方法运行。辅助方法对
mongosh
用户来说很方便,但它们返回的信息级别可能与数据库命令不同。如果不追求方便或需要额外的返回字段,请使用数据库命令。
兼容性
此命令可用于以下环境中托管的部署:
MongoDB Atlas:用于云中 MongoDB 部署的完全托管服务
重要
M 0 、M 2 、M 5和 M 10 + 集群不支持此命令。 有关更多信息,请参阅不支持的命令。
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
语法
该命令具有以下语法:
db.runCommand( { dropRole: "<role>", writeConcern: { <write concern> }, comment: <any> } )
命令字段
该命令具有以下字段:
字段 | 类型 | 说明 |
---|---|---|
| 字符串 | The name of the user-defined role to remove from the database. |
| 文档 | |
| any | 可选。用户提供的待附加到该命令的注释。设置后,该注释将与该命令的记录一起出现在以下位置:
注释可以是任何有效的 BSON 类型(字符串、整型、对象、数组等)。 |
行为
身份验证
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.
必需的访问权限
例子
The following operations remove the readPrices
role from the
products
database:
use products db.runCommand( { dropRole: "readPrices", writeConcern: { w: "majority" } } )