Docs Menu

ユーザーsInfo

usersInfo

Returns information about one or more users.

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

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

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

注意

This command is not supported in MongoDB Atlas. For information on Atlas support for all commands, see Unsupported Commands.

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

db.runCommand(
{
usersInfo: <various>,
showCredentials: <Boolean>,
showCustomData: <Boolean>,
showPrivileges: <Boolean>,
showAuthenticationRestrictions: <Boolean>,
filter: <document>,
comment: <any>
}
)

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

フィールド
タイプ
説明

usersInfo

various

The user(s) about whom to return information.

The argument to usersInfo has multiple forms depending on the requested information. See usersInfo: <various>.

showCredentials

ブール値

任意。 ユーザーのパスワード ハッシュを表示するには、 をtrueに設定します。

デフォルトでは、このフィールドは false です。

showCustomData

ブール値

任意。 Set to false to omit the user's customData from the output.

デフォルトでは、このフィールドは true です。

バージョン 5.2 で追加

showPrivileges

ブール値

任意。 をtrueに設定すると、継承されたロールの展開情報を含むユーザーの完全な権限セットが表示されます。

デフォルトでは、このフィールドは false です。

すべてのユーザーを表示する場合は、このフィールドを指定できません。

showAuthenticationRestrictions

ブール値

Optional. Set to true to show the user's authentication restrictions.

デフォルトでは、このフィールドは false です。

すべてのユーザーを表示する場合は、このフィールドを指定できません。

filter

ドキュメント

任意。 フィルター条件に一致するユーザーの情報を返すために$matchステージ条件を指定するドキュメント。

comment

any

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

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

{ usersInfo: <various> }

The argument to usersInfo has multiple forms depending on the requested information:

Argument
戻り値

{ usersInfo: 1 }

Returns information about the users in the database where the command is run.

mongosh provides the db.getUsers() helper for this invocation of the command.

{ usersInfo: <username> }

Return information about the a specific user that exists in the database where the command is run.

mongosh provides the db.getUser() helper for this invocation of the command.

{ usersInfo: { user: <name>, db: <db> } }

Returns information about the user specified by the name and database.

{ usersInfo: [ { user: <name>, db: <db> }, ... ] }
{ usersInfo: [ <username1>, ... ] }

指定したユーザーに関する情報を返します。

{ forAllDBs: true }

Returns information about users in all databases.

Users can always view their own information.

To view another user's information, the user running the command must have privileges that include the viewUser action on the other user's database.

The following information can be returned by the usersInfo depending on the options specified:

{
"users" : [
{
"_id" : "<db>.<username>",
"userId" : <UUID>,
"user" : "<username>",
"db" : "<db>",
"mechanisms" : [ ... ],
"customData" : <document>,
"roles" : [ ... ],
"credentials": { ... }, // only if showCredentials: true
"inheritedRoles" : [ ... ], // only if showPrivileges: true or showAuthenticationRestrictions: true
"inheritedPrivileges" : [ ... ], // only if showPrivileges: true or showAuthenticationRestrictions: true
"inheritedAuthenticationRestrictions" : [ ] // only if showPrivileges: true or showAuthenticationRestrictions: true
"authenticationRestrictions" : [ ... ] // only if showAuthenticationRestrictions: true
},
...
],
"ok" : 1
}

To see information and privileges, but not the credentials, for the user "Kari" defined in "home" database, run the following command:

db.runCommand(
{
usersInfo: { user: "Kari", db: "home" },
showPrivileges: true
}
)

To view a user that exists in the current database, you can specify the user by name only. For example, if you are in the home database and a user named "Kari" exists in the home database, you can run the following command:

db.getSiblingDB("home").runCommand(
{
usersInfo: "Kari",
showPrivileges: true
}
)

To view info for several users, use an array, with or without the optional fields showPrivileges and showCredentials. For example:

db.runCommand( {
usersInfo: [ { user: "Kari", db: "home" }, { user: "Li", db: "myApp" } ],
showPrivileges: true
} )

To view all users on the database the command is run, use a command document that resembles the following:

db.runCommand( { usersInfo: 1 } )

すべてのユーザーを表示する場合は、 showCredentialsオプションを指定できますが、 showPrivilegesまたはshowAuthenticationRestrictionsオプションは指定できません。

The usersInfo command can accept a filter document to return information for users that match the filter condition.

To view all users in the current database who have the specified role, use a command document that resembles the following:

db.runCommand( { usersInfo: 1, filter: { roles: { role: "root", db: "admin" } } } )

すべてのユーザーを表示する場合は、 showCredentialsオプションを指定できますが、 showPrivilegesまたはshowAuthenticationRestrictionsオプションは指定できません。

The usersInfo command can accept a filter document to return information for users that match the filter condition.

The following operation returns all users that have SCRAM-SHA-1 credentials. Specifically, the command returns all users across all databases and then uses the $match stage to apply the specified filter to the users.

db.runCommand( { usersInfo: { forAllDBs: true}, filter: { mechanisms: "SCRAM-SHA-1" } } )

すべてのユーザーを表示する場合は、 showCredentialsオプションを指定できますが、 showPrivilegesまたはshowAuthenticationRestrictionsオプションは指定できません。

バージョン 5.2 の新機能: usersInfoの出力からユーザーのカスタム データを除外するには、 showCustomDataオプションをfalseに設定します。

createUserコマンドを使用して、 productsデータベースにaccountAdmin01という名前のユーザーを作成します。

db.getSiblingDB("products").runCommand( {
createUser: "accountAdmin01",
pwd: passwordPrompt(),
customData: { employeeId: 12345 },
roles: [ { role: 'readWrite', db: 'products' } ]
} )

ユーザーには{ employeeId: 12345 }customDataフィールドが含まれています。

ユーザーを取得して出力からカスタム データを除外するには、 showCustomDatafalseに設定してusersInfoを実行します。

db.getSiblingDB("products").runCommand ( {
usersInfo: "accountAdmin01",
showCustomData: false
} )

出力例:

{
users: [
{
_id: 'products.accountAdmin01',
userId: UUID("0955afc1-303c-4683-a029-8e17dd5501f4"),
user: 'accountAdmin01',
db: 'products',
roles: [ { role: 'readWrite', db: 'products' } ],
mechanisms: [ 'SCRAM-SHA-1', 'SCRAM-SHA-256' ]
}
],
ok: 1
}