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()方法具有以下参数:

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:args文档支持以下字段:

Field字段Type类型Description描述
showCredentials boolean Optional.可选。Set the field to true to display the user’s password hash. 将该字段设置为true以显示用户的密码哈希。By default, this field is false.默认情况下,此字段为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. 将该字段设置为true以显示用户的全部权限集,包括继承角色的扩展信息。By default, this field is false. 默认情况下,此字段为falseIf viewing all users, you cannot specify this field.如果查看所有用户,则不能指定此字段。
showAuthenticationRestrictions boolean Optional.可选。Set the field to true to show the user’s authentication restrictions. 将该字段设置为true以显示用户的身份验证限制。By default, this field is false. 默认情况下,此字段为falseIf 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.指定$match阶段条件以返回与筛选条件匹配的用户信息的文档。

New in version 4.0.版本4.0中的新功能。

db.getUser() wraps the usersInfo: <username> command.包装usersInfo: <username>命令。

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.要查看其他用户的信息,必须对其他用户的数据库执行viewUser操作

Users can view their own information.用户可以查看自己的信息。

Example示例

The following sequence of operations returns information about the appClient user on the accounts database:以下操作序列将返回accounts数据库中有关appClient用户的信息:

use accounts
db.getUser("appClient")