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