定義
grantRolesToRoleTip
In
mongosh, this command can also be run through thedb.grantRolesToRole()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.The
grantRolesToRolecommand affects roles on the database where the command runs.
このコマンドの構文は、次のとおりです。
db.runCommand( { grantRolesToRole: "<role>", roles: [ { role: "<role>", db: "<database>" }, ... ], 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 grantRolesToRole runs, you can either specify the role with the name of the role:
"readWrite"
または、次のように、ドキュメントを使用してロールを指定することもできます。
{ role: "<role>", db: "<database>" }
別のデータベースに存在するロールを指定するには、 ドキュメントを使用してロールを指定します。
互換性
このコマンドは、次の環境でホストされている配置で使用できます。
- MongoDB Atlas はクラウドでの MongoDB 配置のための完全管理サービスです
重要
このコマンドは、M0 および Flex クラスターではサポートされていません。詳細については、サポートされていないコマンド を参照してください。
MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン
MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン
動作
ロールはデータベース内の他のロールから権限を継承することができます。admin データベースで作成されたロールは、任意のデータベースのロールから権限を継承できます。
必要なアクセス権
例
The following grantRolesToRole command updates the productsReaderWriter role in the products database to inherit the privileges of the productsReader role in the products database:
use products db.runCommand( { grantRolesToRole: "productsReaderWriter", roles: [ "productsReader" ], writeConcern: { w: "majority" , wtimeout: 5000 } } )