db.getUser()

On this page

Definition

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

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

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

The args document supports the following fields:

FieldTypeDescription
showCredentialsbooleanOptional. Set the field to true to display the user’s password hash. By default, this field is false .
showPrivilegesbooleanOptional. Set the field to true to show the user’s full set of privileges, including expanded information for the inherited roles. By default, this field is false . If viewing all users, you cannot specify this field.
showAuthenticationRestrictionsbooleanOptional. Set the field to true to show the user’s authentication restrictions. By default, this field is false . If viewing all users, you cannot specify this field.

db.getUser() wraps the usersInfo command.

Required Access

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

Users can view their own information.

Example

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

use accounts
db.getUser("appClient")