定义
dropRole从运行命令的数据库中删除用户定义的角色。
提示
In
mongosh, this command can also be run through thedb.dropRole()helper method.Helper methods are convenient for
mongoshusers, but they may not return the same level of information as database commands. In cases where the convenience is not needed or the additional return fields are required, use the database command.
兼容性
此命令可用于以下环境中托管的部署:
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
重要
MongoDB Atlas 集群不支持此命令。有关 Atlas 对所有命令的支持的信息,请参阅不支持的命令。
语法
该命令具有以下语法:
db.runCommand( { dropRole: "<role>", writeConcern: { <write concern> }, comment: <any> } )
命令字段
该命令具有以下字段:
字段 | 类型 | 说明 |
|---|---|---|
| 字符串 | 要从数据库中删除的用户定义角色的名称。 |
| 文档 | |
| any | 可选。用户提供的待附加到该命令的注释。设置后,该注释将与该命令的记录一起出现在以下位置:
注释可以是任何有效的 BSON 类型(字符串、整型、对象、数组等)。 |
行为
身份验证
在mongod上删除角色时,之前通过身份验证的用户仍会保持登录数据库的状态,但会立即失去该角色的权限。
在mongos上删除角色时,以前经过身份验证的用户仍保持登录数据库的状态,但在缓存刷新时会失去该角色的特权。 缓存会在userCacheInvalidationIntervalSecs参数指定的时间后自动刷新,或者在运行invalidateUserCache命令时手动刷新。
必需的访问权限
例子
以下操作从products数据库中删除readPrices角色:
use products db.runCommand( { dropRole: "readPrices", writeConcern: { w: "majority" } } )