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

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

rolesInfo

ユーザー定義ロール組み込みロールの両方を含む指定されたロールの継承と特権情報を返します。

The rolesInfo command 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>
}
)

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

フィールド
タイプ
説明

rolesInfo

string、ドキュメント、配列、または整数

The role(s) to return information about. For the syntax for specifying roles, see Behavior.

showAuthenticationRestrictions

ブール値

任意。 出力に認証制限を含めるには、このフィールドをtrueに設定します。 認証制限は、このロールを持つユーザーが接続できる IP アドレスと接続元を示します。

デフォルトでは、このフィールドはfalseであり、 rolesInfoの出力には認証制限が含まれていません。

showBuiltinRoles

ブール値

任意。 rolesInfoフィールドが1に設定されている場合は、出力に組み込みロールを含めるために、 showBuiltinRolestrueに設定します。 デフォルトでは、このフィールドはfalseに設定されており、 rolesInfo: 1の出力にはユーザー定義ロールのみが表示されます。

showPrivileges

ブール値

任意。 フィールドをtrueに設定すると、他のロールから継承される権限と直接定義された権限の両方を含むロール権限が表示されます。 デフォルトでは、コマンドは、このロールが特権を継承するロールのみを返し、特定の特権は返しません。

comment

any

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

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

現在のデータベースからロールを指定するには、次のように、ロールを名前で指定します。

{ 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.role

ロールの名前。

rolesInfo.db

ロールが定義されているデータベース。 すべてのデータベースには組み込みロール があります。 データベースにはユーザー定義のロールがある場合もあります。

rolesInfo.isBuiltin

trueの値は、ロールが組み込みロール であることを示します。 falseの値は、ロールがユーザー定義ロール であることを示します。

rolesInfo.roles

このロールに特権を直接付与するロールと、ロールが定義されているデータベース。

rolesInfo.inheritedRoles

All roles from which this role inherits privileges. This includes the roles in the rolesInfo.roles array as well as the roles from which the roles in the rolesInfo.roles array 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.privileges

The privileges directly specified by this role; i.e. the array excludes privileges inherited from other roles. By default the output does not include the privileges field. To include the field, specify showPrivileges: true when running the rolesInfo command.

各特権ドキュメントは、リソースと、そのリソースに対して許可されるアクションを指定します。

rolesInfo.inheritedPrivileges

All privileges granted by this role, including those inherited from other roles. By default the output does not include the inheritedPrivileges field. To include the field, specify showPrivileges: true when running the rolesInfo command.

各特権ドキュメントは、リソースと、そのリソースに対して許可されるアクションを指定します。

このセクションの例では、 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
}