定義
rolesInfoユーザー定義ロールと組み込みロールの両方を含む指定されたロールの継承と特権情報を返します。
The
rolesInfocommand can also retrieve all roles scoped to a database.
互換性
このコマンドは、次の環境でホストされている配置で使用できます。
- MongoDB Atlas はクラウドでの MongoDB 配置のための完全管理サービスです
注意
このコマンドは、すべての MongoDB Atlas クラスターでサポートされています。すべてのコマンドに対する Atlas のサポートについては、「サポートされていないコマンド」を参照してください。
MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン
MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン
構文
このコマンドの構文は、次のとおりです。
db.runCommand( { rolesInfo: { role: <name>, db: <db> }, showAuthenticationRestrictions: <Boolean>, showBuiltinRoles: <Boolean>, showPrivileges: <Boolean>, comment: <any> } )
コマンドフィールド
このコマンドは、次のフィールドを使用します。
フィールド | タイプ | 説明 |
|---|---|---|
| string、ドキュメント、配列、または整数 | The role(s) to return information about. For the syntax for specifying roles, see Behavior. |
| ブール値 | 任意。 出力に認証制限を含めるには、このフィールドを デフォルトでは、このフィールドは |
| ブール値 | 任意。 |
| ブール値 | 任意。 フィールドを |
| any | 任意。このコマンドに添付するユーザー指定のコメント。設定すると、このコメントは以下の場所にこのコマンドの記録と合わせて表示されます。
コメントには、有効な BSON 型(string, integer, object, array など)を使用できます。 |
動作
1 つのロールの情報を返す
現在のデータベースからロールを指定するには、次のように、ロールを名前で指定します。
{ rolesInfo: "<rolename>" }
別のデータベースからロールを指定するには、ロールとデータベースを指定するドキュメントでロールを指定します。
{ rolesInfo: { role: "<rolename>", db: "<database>" } }
複数のロールの情報を返す
複数のロールを指定するには、配列を使用します。 配列内の各ロールをドキュメントまたは string として指定します。 コマンドが実行されるデータベースにロールが存在する場合にのみ string を使用します。
{ rolesInfo: [ "<rolename>", { role: "<rolename>", db: "<database>" }, ... ] }
データベース内のすべてのロールの情報を返す
コマンドが実行されるデータベース内のすべてのロールを指定するには、 rolesInfo: 1を指定します。 デフォルトでは、MongoDB は データベース内のすべてのユーザー定義のロールを表示します。 組み込みロールも含めるには、パラメータと値のペアshowBuiltinRoles: trueを含めます。
{ rolesInfo: 1, showBuiltinRoles: true }
必要なアクセス権
ロールの情報を表示するには、ロールが明示的に付与されているか、ロールのデータベースに対してviewRoleアクションを持っている必要があります。
出力
rolesInfo.dbロールが定義されているデータベース。 すべてのデータベースには組み込みロール があります。 データベースにはユーザー定義のロールがある場合もあります。
rolesInfo.isBuiltintrueの値は、ロールが組み込みロール であることを示します。falseの値は、ロールがユーザー定義ロール であることを示します。
rolesInfo.inheritedRolesAll roles from which this role inherits privileges. This includes the roles in the
rolesInfo.rolesarray as well as the roles from which the roles in therolesInfo.rolesarray inherit privileges. All privileges apply to the current role. The documents in this field list the roles and the databases on which they are defined.
rolesInfo.privilegesThe privileges directly specified by this role; i.e. the array excludes privileges inherited from other roles. By default the output does not include the
privilegesfield. To include the field, specifyshowPrivileges: truewhen running therolesInfocommand.
rolesInfo.inheritedPrivilegesAll privileges granted by this role, including those inherited from other roles. By default the output does not include the
inheritedPrivilegesfield. To include the field, specifyshowPrivileges: truewhen running therolesInfocommand.
例
このセクションの例では、 rolesInfoコマンドを使用して次の操作を実行する方法を示します。
単一のロールの情報の表示
次のコマンドは、 productsデータベースで定義されているロールassociateのロール継承情報を返します。
db.runCommand( { rolesInfo: { role: "associate", db: "products" } } )
次のコマンドは、コマンドが実行されるデータベース上のロールsiteManagerのロール継承情報を返します。
db.runCommand( { rolesInfo: "siteManager" } )
次のコマンドは、 productsデータベースで定義されたロールassociateのロール継承と特権の両方を返します。
db.runCommand( { rolesInfo: { role: "associate", db: "products" }, showPrivileges: true } )
複数のロールに関する情報の表示
次のコマンドは、2 つの異なるデータベース上の 2 つのロールに関する情報を返します。
db.runCommand( { rolesInfo: [ { role: "associate", db: "products" }, { role: "manager", db: "resources" } ] } )
次の例では、ロールの継承と特権の両方が返されます。
db.runCommand( { rolesInfo: [ { role: "associate", db: "products" }, { role: "manager", db: "resources" } ], showPrivileges: true } )
データベースのすべてのユーザー定義ロールの表示
次の操作は、 コマンドが実行され、 特権を含むデータベース上のすべてのユーザー定義のロールを返します。
db.runCommand( { rolesInfo: 1, showPrivileges: true } )
出力例(読みやすくするために短縮しています)
{ roles: [ { _id: 'products.associate', role: 'associate', db: 'products', privileges: [ { resource: { db: 'products', collection: '' }, actions: [ 'bypassDocumentValidation' ] } ], roles: [ { role: 'readWrite', db: 'products' } ], isBuiltin: false, inheritedRoles: [ { role: 'readWrite', db: 'products' } ], inheritedPrivileges: [ { resource: { db: 'products', collection: '' }, actions: [ 'bypassDocumentValidation' ] }, { resource: { db: 'products', collection: '' }, actions: [ 'changeStream', 'collStats', 'compactStructuredEncryptionData', ... ] }, ... ] } ], ok: 1 }
データベースのすべてのユーザー定義ロールと組み込みロールの表示
次の操作では、組み込みロールとユーザー定義ロールの両方を含む、 コマンドが実行されるデータベース上のすべてのロールが返されます。
db.runCommand( { rolesInfo: 1, showBuiltinRoles: true } )
出力例(読みやすくするために短縮しています)
{ roles: [ { role: 'enableSharding', db: 'products', isBuiltin: true, roles: [], inheritedRoles: [] }, { role: 'userAdmin', db: 'products', isBuiltin: true, roles: [], inheritedRoles: [] }, { role: 'read', db: 'products', isBuiltin: true, roles: [], inheritedRoles: [] }, ... ], ok: 1 }
ロールの認証制限の表示
次の操作は、 productsデータベース上のすべてのユーザー定義ロールを返し、認証制限を含みます。
db.runCommand( { rolesInfo: 1, showAuthenticationRestrictions: true } )
出力例:
{ roles: [ { _id: 'products.associate', role: 'associate', db: 'products', roles: [ { role: 'readWrite', db: 'products' } ], authenticationRestrictions: [ [ { clientSource: [ '198.51.100.0' ] } ] ], isBuiltin: false, inheritedRoles: [ { role: 'readWrite', db: 'products' } ], inheritedAuthenticationRestrictions: [ [ { clientSource: [ '198.51.100.0' ] } ] ] } ], ok: 1 }