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:

db.getUser( "<username>", {
   showCredentials: <Boolean>,
   showPrivileges: <Boolean>,
   showAuthenticationRestrictions: <Boolean>,
   filter: <document>
} )
Parameter参数Type类型Description描述
username string The name of the user for which to retrieve information.
args document Optional.可选。A document specifying additional arguments.

The args document supports the following fields:

Field字段Type类型Description描述
showCredentials boolean Optional.可选。Set the field to true to display the user’s password hash. By default, this field is false.
showPrivileges boolean Optional.可选。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.
showAuthenticationRestrictions boolean Optional.可选。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.
filter document

Optional.可选。A document that specifies $match stage conditions to return information for users that match the filter conditions.

New in version 4.0.版本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 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")