Docs Menu
Docs Home
/
MongoDB Manual
/ / /

db.getUsers()

On this page

  • Definition
  • Compatibility
  • Required Access
  • Example
db.getUsers(<options>)

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:

db.getUsers( {
showCredentials: <Boolean>,
filter: <document>
} )
Field
Type
Description
showCredentials
boolean
Optional. Set the field to true to display the user's password hash. By default, this field is false.
filter
document
Optional. A document that specifies $match stage conditions to return information for users that match the filter conditions.

For more information, see usersInfo.

This method is available in deployments hosted in the following environments:

Important

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

  • MongoDB Enterprise: The subscription-based, self-managed version of MongoDB

  • MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB

To view another user's information, you must have the viewUser action on the other user's database.

Users can view their own information.

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

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

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

When viewing all users, you can specify the showCredentials option but not the showPrivileges or the showAuthenticationRestrictions options.

Back

db.getUser