定義
db.getUsers(<options>)データベース内のすべてのユーザーの情報を返します。
db.getUsers()wraps theusersInfo: 1command.The
db.getUsers()method can take the following options:db.getUsers( { showCredentials: <Boolean>, showCustomData: <Boolean>, filter: <document> } ) フィールドタイプ説明showCredentialsブール値
任意。 ユーザーのパスワード ハッシュを表示するには、 を
trueに設定します。デフォルトでは、このフィールドは
falseです。showCustomDataブール値
任意。 Set to
falseto omit the user'scustomDatafrom 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 }