On this page
revokePrivilegesFromRole
在本页面
Definition
revokePrivilegesFromRole
- 从运行命令的数据库的user-defined角色中删除指定的特权。 revokePrivilegesFromRole命令具有以下语法:
{
revokePrivilegesFromRole: "<role>",
privileges:
[
{ resource: { <resource> }, actions: [ "<action>", ... ] },
...
],
writeConcern: <write concern document>
}
revokePrivilegesFromRole命令具有以下字段:
Field | Type | Description |
---|---|---|
revokePrivilegesFromRole |
string | 撤消特权的user-defined角色。 |
privileges |
array | 从角色中删除的一系列特权。有关特权格式的更多信息,请参见privileges。 |
writeConcern |
document | 可选的。修改的write concern级别。 writeConcern 文档具有与getLastError命令相同的字段。 |
Behavior
要撤消特权,resource document模式必须与该特权的resource
字段“完全匹配”。 actions
字段可以是子集或完全匹配。
例如,考虑具有以下特权的products
数据库中的角色accountRole
,该特权将products
数据库指定为资源:
{
"resource" : {
"db" : "products",
"collection" : ""
},
"actions" : [
"find",
"update"
]
}
您不能仅从products
数据库中的一个集合中撤消find
和/或update
。以下操作不会更改角色:
use products
db.runCommand(
{
revokePrivilegesFromRole: "accountRole",
privileges:
[
{
resource : {
db : "products",
collection : "gadgets"
},
actions : [
"find",
"update"
]
}
]
}
)
db.runCommand(
{
revokePrivilegesFromRole: "accountRole",
privileges:
[
{
resource : {
db : "products",
collection : "gadgets"
},
actions : [
"find"
]
}
]
}
)
要从角色accountRole
撤消"find"
和/或"update"
操作,您必须完全匹配资源文档。例如,以下操作仅撤销现有特权中的"find"
操作。
use products
db.runCommand(
{
revokePrivilegesFromRole: "accountRole",
privileges:
[
{
resource : {
db : "products",
collection : ""
},
actions : [
"find"
]
}
]
}
)
Required Access
您必须在数据库上具有revokeRole action特权目标,才能撤消该特权。如果特权针对多个数据库或cluster
资源,则必须对admin
数据库执行revokeRole操作。
Example
以下操作从products
数据库的associates
角色中删除多个特权:
use products
db.runCommand(
{
revokePrivilegesFromRole: "associate",
privileges:
[
{
resource: { db: "products", collection: "" },
actions: [ "createCollection", "createIndex", "find" ]
},
{
resource: { db: "products", collection: "orders" },
actions: [ "insert" ]
}
],
writeConcern: { w: "majority" }
}
)