定义
db.dropRole( rolename, writeConcern )从运行该方法的数据库中删除用户定义的角色。
重要
mongosh 方法
This page documents a
mongoshmethod. This is not the documentation for database commands or language-specific drivers, such as Node.js.有关数据库命令,请参阅
dropRole命令。如需了解 MongoDB API 驱动程序,请参阅特定语言的 MongoDB 驱动程序文档。
The
db.dropRole()method takes the following arguments:
兼容性
此方法可用于以下环境中托管的部署:
重要
MongoDB Atlas 集群不支持此命令。有关 Atlas 对所有命令的支持的信息,请参阅不支持的命令。
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
行为
身份验证
在mongod上删除角色时,之前通过身份验证的用户仍会保持登录数据库的状态,但会立即失去该角色的权限。
在mongos上删除角色时,以前经过身份验证的用户仍保持登录数据库的状态,但在缓存刷新时会失去该角色的特权。 缓存会在userCacheInvalidationIntervalSecs参数指定的时间后自动刷新,或者在运行invalidateUserCache命令时手动刷新。
副本集(Replica Set)
If run on a replica set, db.dropRole() is executed using "majority" write concern by default.
必需的访问权限
例子
以下操作从products数据库中删除readPrices角色:
use products db.dropRole( "readPrices", { w: "majority" } )