- Reference >
mongoshMethods >- User Management Methods >
- db.getUser()
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:Parameter Type Description usernamestring The name of the user for which to retrieve information. argsdocument Optional. A document specifying additional arguments. The
argsdocument supports the following fields:Field Type Description showCredentialsboolean Optional. Set to
trueto display the user’s password hash.By default, this field is
false.showCustomDataboolean Optional. Set to
falseto omit the user’scustomDatafrom the output.By default, this field is
true.New in version 5.2.
showPrivilegesboolean Optional. Set to
trueto 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.
showAuthenticationRestrictionsboolean Optional. Set to
trueto show the user’s authentication restrictions.By default, this field is
false.If viewing all users, you cannot specify this field.
filterdocument Optional. A document that specifies
$matchstage conditions to return information for users that match the filter conditions.New in version 4.0.
db.getUser()wraps theusersInfo: <username>command.For details on output, see
usersInfo.
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.
Examples¶
The following operations return information about an example
appClient user in an accounts database:
Example output:
Omit Custom Data from Output¶
New in version 5.2: To omit a user’s custom data from the db.getUser() output,
set the showCustomData option to false.
Use the createUser command to create a user named
accountAdmin01 on the products database:
The user contains a customData field of { employeeId: 12345 }.
To retrieve the user but omit the custom data from the output, run
db.getUser() with showCustomData set to false:
Example output: