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

db.getUsers()(mongoshメソッド)

db.getUsers(<options>)

データベース内のすべてのユーザーの情報を返します。

db.getUsers() wraps the usersInfo: 1 command.

The db.getUsers() method can take the following options:

db.getUsers( {
showCredentials: <Boolean>,
showCustomData: <Boolean>,
authenticatedMechanism: <string>,
filter: <document>
} )
フィールド
タイプ
説明

showCredentials

ブール値

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

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

showCustomData

ブール値

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

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

バージョン5.2の新機能。

authenticatedMechanism

string

バージョン9.0の新機能。

任意。サポートされている認証メカニズムを表すstringに設定し、db.getUsers()がユーザーの承認情報をどこで検索するかを決定します。メカニズムとその関連stringのリストについては、authenticationMechanismsを参照してください。

このフィールドが指定されていない場合、db.getUsers()は、$externalデータベースで定義されたユーザーについてはLDAPから、SCRAMユーザーについてはローカル承認データベースから情報を返します。

filter

ドキュメント

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

詳細については、usersInfo を参照してください。

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

重要

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

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

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

他のユーザーの情報を表示するには、他のユーザーのデータベースに対してviewUserアクションが必要です。

ユーザーは自分の情報を表示できます。

The db.getUsers() method can accept a filter document to return information for users that match the filter condition.

現在のデータベースでSCRAM-SHA-256資格情報を持つすべてのユーザーを表示するには、

db.getUsers({ filter: { mechanisms: "SCRAM-SHA-256" } })

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

バージョン 5.2 の新機能:

To omit users' custom data from the db.getUsers() output, set the showCustomData option to false.

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

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

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

To retrieve the user but omit the custom data from the output, run db.getUsers() with showCustomData set to false:

db.getSiblingDB("products").getUsers( { 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
}