On this page本页内容
usersInfo¶Returns information about one or more users.
The usersInfo command has the following form:
The command has the following fields:
usersInfo |
various | The user(s) about whom to return information. The argument to |
showCredentials |
boolean | false. |
showPrivileges |
boolean | false. If viewing all users, you cannot specify this field. |
showAuthenticationRestrictions |
boolean | false. If viewing all users, you cannot specify this field. |
filter |
document |
|
comment |
any |
A comment can be any valid BSON type (string, integer, object, array, etc).
|
usersInfo: <various>¶The argument to usersInfo has multiple forms depending on the requested information:
{ usersInfo: 1 } |
Returns information about the users in the database where the command is run. The |
{ usersInfo: <username> } |
Return information about the a specific user that exists in the database where the command is run. The |
{ usersInfo: { user: <name>, db: <db> } } |
Returns information about the user specified by the name and database. |
{ usersInfo: [ { user: <name>, db: <db> }, ... ] }{ usersInfo: [ <username1>, ... ] } |
Returns information about the specified users. |
{ forAllDBs: true } |
Returns information about users in all databases.
|
Users can always view their own information.
To view another user’s information, the user running the command must have privileges that include the viewUser action on the other user’s database.
The following information can be returned by the usersInfo depending on the options specified:
To see information and privileges, but not the credentials, for the user "Kari" defined in "home" database, run the following command:
To view a user that exists in the current database, you can specify the user by name only. For example, if you are in the home database and a user named "Kari" exists in the home database, you can run the following command:
To view info for several users, use an array, with or without the optional fields showPrivileges and showCredentials. For example:例如:
To view all users on the database the command is run, use a command document that resembles the following:
When viewing all users, you can specify the showCredentials option but not the showPrivileges or the showAuthenticationRestrictions options.
New in version 4.0:The usersInfo command can accept a filter document to return information for users that match the filter condition.
To view all users in the current database who have the specified role, use a command document that resembles the following:
When viewing all users, you can specify the showCredentials option but not the showPrivileges or the showAuthenticationRestrictions options.
SCRAM-SHA-1 Credentials¶New in version 4.0:The usersInfo command can accept a filter document to return information for users that match the filter condition.
The following operation returns all users that have SCRAM-SHA-1 credentials. Specifically, the command returns all users across all databases and then uses the $match stage to apply the specified filter to the users.
When viewing all users, you can specify the showCredentials option but not the showPrivileges or the showAuthenticationRestrictions options.