db.getUsers()

On this page本页内容

Definition定义

db.getUsers(<options>)

Returns information for all the users in the database.返回数据库中所有用户的信息。

db.getUsers() wraps the usersInfo: 1 command.包装了usersInfo: 1命令。

The db.getUsers() method can take the following options:db.getUsers()方法可以采用以下选项:

db.getUsers( {
   showCredentials: <Boolean>,
   filter: <document>
} )
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
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中的新功能。

For more information, see usersInfo.有关更多信息,请参阅usersInfo

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示例

View All Users for a Database that Match the Specified Filter查看与指定筛选器匹配的数据库的所有用户

New in version 4.0:4.0版中新增:The db.getUsers() method can accept a filter document to return information for users that match the filter condition.db.getUsers()方法可以接受filter文档,以返回与筛选条件匹配的用户的信息。

To view all users for the current database who have SCRAM-SHA-256 credentials:要查看当前数据库中拥有SCRAM-SHA-256凭据的所有用户:

db.getUsers({ filter: { mechanisms: "SCRAM-SHA-256" } })

When viewing all users, you can specify the showCredentials option but not the showPrivileges or the showAuthenticationRestrictions options.查看所有用户时,可以指定showCredentials选项,但不能指定showPrivilegesshowAuthenticationRestrictions选项。