db.getUser()

Definition

  • db.getUser(username, args)
  • Returns user information for a specified user. Run this method on theuser’s database. The user must exist on the database on which the methodruns.

The db.getUser() method has the following parameters:

  1. db.getUser( "<username>", {
  2. showCredentials: <Boolean>,
  3. showPrivileges: <Boolean>,
  4. showAuthenticationRestrictions: <Boolean>,
  5. filter: <document>
  6. } )

ParameterTypeDescriptionusernamestringThe name of the user for which to retrieve information.argsdocumentOptional. A document specifying additional arguments.

The args document supports the following fields:

FieldTypeDescriptionshowCredentialsbooleanOptional. Set the field to true to display the user’s password hash. By default, thisfield is false.showPrivilegesbooleanOptional. Set the field to true to show the user’s full set of privileges, includingexpanded information for the inherited roles. By default, this fieldis false. If viewing all users, you cannot specify this field.showAuthenticationRestrictionsbooleanOptional. Set the field to true to show the user’s authentication restrictions. Bydefault, this field is false. If viewing all users, you cannot specifythis field.filterdocumentOptional. A document that specifies $match stage conditions toreturn information for users that match the filter conditions.

New in version 4.0.

db.getUser() wraps the usersInfo: <username> command.

For details on output, see

Required Access

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

Users can view their own information.

Example

The following sequence of operations returns information about theappClient user on the accounts database:

  1. use accounts
  2. db.getUser("appClient")