AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
Docs Menu

revokePrivilegesFromRole(データベースコマンド)

revokePrivilegesFromRole

コマンドが実行されるデータベース上のユーザー定義ロールから指定した権限を削除します。

Tip

In mongosh, this command can also be run through the db.revokePrivilegesFromRole() helper method.

Helper methods are convenient for mongosh users, but they may not return the same level of information as database commands. In cases where the convenience is not needed or the additional return fields are required, use the database command.

このコマンドは、次の環境でホストされている配置で使用できます。

  • MongoDB Atlas はクラウドでの MongoDB 配置のための完全管理サービスです

重要

このコマンドは、M0 および Flex クラスターではサポートされていません。詳細については、サポートされていないコマンド を参照してください。

  • MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン

  • MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン

このコマンドの構文は、次のとおりです。

db.runCommand(
{
revokePrivilegesFromRole: "<role>",
privileges: [
{ resource: { <resource> }, actions: [ "<action>", ... ] },
...
],
writeConcern: <write concern document>,
comment: <any>
}
)

このコマンドは、次のフィールドを使用します。

フィールド
タイプ
説明

revokePrivilegesFromRole

string

特権を取り消すユーザー定義のロール。

privileges

配列

ロールから削除する特権の配列。 特権の形式の詳細については、 privilegesを参照してください。

writeConcern

ドキュメント

任意。 操作の 書込み保証( write concern ) のレベル。 詳しくは、 書込み保証(write concern) の仕様を参照してください。

comment

any

任意。このコマンドに添付するユーザー指定のコメント。設定すると、このコメントは以下の場所にこのコマンドの記録と合わせて表示されます。

コメントには、有効な BSON 型(string, integer, object, array など)を使用できます。

特権を取り消すには、リソース ドキュメントパターンがその特権のresourceフィールドと完全に一致する必要がありますactionsフィールドはサブセットまたは完全一致にすることができます。

たとえば、 productsデータベースのロールaccountRoleが、 productsデータベースをリソースとして指定する次の特権を持つとします。

{
"resource" : {
"db" : "products",
"collection" : ""
},
"actions" : [
"find",
"update"
]
}

productsデータベース内の1 つのコレクションのみから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"
]
}
]
}
)

ロール から "find"アクションおよび/または"update"accountRole アクションを取り消すには、リソース ドキュメントと完全に一致する必要があります。たとえば、次の操作は、既存の特権から"find"アクションのみを取り消します。

use products
db.runCommand(
{
revokePrivilegesFromRole: "accountRole",
privileges:
[
{
resource : {
db : "products",
collection : ""
},
actions : [
"find"
]
}
]
}
)

特権を取り消すには、特権ターゲットのデータベースに対してrevokeRoleアクションが必要です。 特権が複数のデータベースまたはclusterリソースを対象としている場合は、 adminデータベースに対してrevokeRoleアクションが必要です。

次の操作により、 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" }
}
)