db.getUsers()

Definition

  • db.getUsers()
  • Returns information for all the users in the database.

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

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

  1. db.getUsers( {
  2. showCredentials: <Boolean>,
  3. filter: <document>
  4. } )

FieldTypeDescriptionshowCredentialsbooleanOptional. Set the field to true to display the user’s password hash. By default, thisfield is false.filterdocumentOptional. A document that specifies $match stage conditions toreturn information for users that match the filter conditions.

New in version 4.0.

For more information, see usersInfo.

Required Access

To view another user’s information, you must have theviewUseraction on theother user’s database.

Users can view their own information.

Example

View All Users for a Database that Match the Specified Filter

New in version 4.0: The db.getUsers() method can accept a filter documentto return information for users that match the filter condition.

To view all users for the current database who have SCRAM-SHA-256credentials:

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

When viewing all users, you can specify the showCredentials optionbut not the showPrivileges or theshowAuthenticationRestrictions options.