对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

db.revokeRolesFromRole()(mongosh方法)

db.revokeRolesFromRole(rolename, roles, writeConcern)

从角色中删除指定的继承角色。

重要

mongosh 方法

This page documents a mongosh method. This is not the documentation for database commands or language-specific drivers, such as Node.js.

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

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

The db.revokeRolesFromRole() method uses the following syntax:

db.revokeRolesFromRole( "<rolename>", [ <roles> ], { <writeConcern> } )

The db.revokeRolesFromRole() method takes the following arguments:

Parameter
类型
说明

rolename

字符串

要撤销的角色的名称。

roles

阵列

要删除的继承角色。

writeConcern

文档

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

roles 字段中,可以指定内置角色用户自定义角色

To specify a role that exists in the same database where db.revokeRolesFromRole() runs, you can either specify the role with the name of the role:

"readWrite"

或者,可以使用文档指定角色,如下所示:

{ role: "<role>", db: "<database>" }

要指定存在于其他数据库中的角色,请使用文档指定该角色。

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

重要

MongoDB Atlas 集群不支持此命令。有关 Atlas 对所有命令的支持的信息,请参阅不支持的命令

If run on a replica set, db.revokeRolesFromRole() is executed using "majority" write concern by default.

必须对数据库执行 revokeRole 动作才能撤消该数据库上的角色。

emea数据库中的purchaseAgents角色继承了其他几个角色的权限,如roles数组中所列:

{
"_id" : "emea.purchaseAgents",
"role" : "purchaseAgents",
"db" : "emea",
"privileges" : [],
"roles" : [
{
"role" : "readOrdersCollection",
"db" : "emea"
},
{
"role" : "readAccountsCollection",
"db" : "emea"
},
{
"role" : "writeOrdersCollection",
"db" : "emea"
}
]
}

The following db.revokeRolesFromRole() operation on the emea database removes two roles from the purchaseAgents role:

use emea
db.revokeRolesFromRole( "purchaseAgents",
[
"writeOrdersCollection",
"readOrdersCollection"
],
{ w: "majority" , wtimeout: 5000 }
)

purchaseAgents角色现在只包含一个角色:

{
"_id" : "emea.purchaseAgents",
"role" : "purchaseAgents",
"db" : "emea",
"privileges" : [],
"roles" : [
{
"role" : "readAccountsCollection",
"db" : "emea"
}
]
}