定義
revokeRolesFromUserロールが存在するデータベース上のユーザーから 1 つ以上のロールを削除します。
Tip
In
mongosh, this command can also be run through thedb.revokeRolesFromUser()helper method.Helper methods are convenient for
mongoshusers, 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 Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン
MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン
重要
This command is not supported in MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.
構文
このコマンドの構文は、次のとおりです。
db.runCommand( { revokeRolesFromUser: "<user>", roles: [ { role: "<role>", db: "<database>" } | "<role>", ... ], writeConcern: { <write concern> }, comment: <any> } )
コマンドフィールド
このコマンドは、次のフィールドを使用します。
フィールド | タイプ | 説明 |
|---|---|---|
| string | ロールを削除するユーザー。 |
| 配列 | ユーザーから削除するロール。 |
| ドキュメント | 任意。 操作の 書込み保証( write concern ) のレベル。 詳しくは、 書込み保証(write concern) の仕様を参照してください。 |
| any | 任意。このコマンドに添付するユーザー指定のコメント。設定すると、このコメントは以下の場所にこのコマンドの記録と合わせて表示されます。
コメントには、有効な BSON 型(string, integer, object, array など)を使用できます。 |
rolesフィールドでは、組み込みロールとユーザー定義ロールの両方を指定できます。
To specify a role that exists in the same database where revokeRolesFromUser runs, you can either specify the role with the name of the role:
"readWrite"
または、次のように、ドキュメントを使用してロールを指定することもできます。
{ role: "<role>", db: "<database>" }
別のデータベースに存在するロールを指定するには、 ドキュメントを使用してロールを指定します。
必要なアクセス権
データベースのロールを取り消すには、データベースに対してrevokeRoleアクションが必要です。
例
productsデータベース内のaccountUser01ユーザーには次のロールがあります。
"roles" : [ { "role" : "assetsReader", "db" : "assets" }, { "role" : "read", "db" : "stock" }, { "role" : "readWrite", "db" : "products" } ]
The following revokeRolesFromUser command removes the two of the user's roles: the read role on the stock database and the readWrite role on the products database, which is also the database on which the command runs:
use products db.runCommand( { revokeRolesFromUser: "accountUser01", roles: [ { role: "read", db: "stock" }, "readWrite" ], writeConcern: { w: "majority" } } )
productsデータベース内のユーザーaccountUser01に残りのロールが 1 つだけになりました。
"roles" : [ { "role" : "assetsReader", "db" : "assets" } ]