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>,
filter: <document>
} )
フィールド
タイプ
説明

showCredentials

ブール値

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

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

showCustomData

ブール値

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

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

バージョン5.2の新機能。

filter

ドキュメント

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

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

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

重要

このコマンドは、MongoDB Atlas クラスターではサポートされていません。すべてのコマンドに対する Atlas のサポートについては、「サポートされていないコマンド」を参照してください。

  • 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
}