revokePrivilegesFromRole

在本页面

Definition

{
  revokePrivilegesFromRole: "<role>",
  privileges:
      [
        { resource: { <resource> }, actions: [ "<action>", ... ] },
        ...
      ],
  writeConcern: <write concern document>
}

revokePrivilegesFromRole命令具有以下字段:

FieldTypeDescription
revokePrivilegesFromRolestring撤消特权的user-defined角色。
privilegesarray从角色中删除的一系列特权。有关特权格式的更多信息,请参见privileges
writeConcerndocument可选的。修改的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" }
   }
)