OPTIONS

usersInfo

Definition

usersInfo

Returns information about one or more users. To match a single user on the database, use the following form:

{ usersInfo: { user: <name>, db: <db> },
  showCredentials: <Boolean>,
  showPrivileges: <Boolean>
}

The command has the following fields:

Field Type Description
usersInfo various The user(s) about whom to return information. See Behavior for type and syntax.
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.

Required Access

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.

Behavior

The argument to the usersInfo command has multiple forms depending on the requested information:

Specify a Single User

In the usersInfo field, specify a document with the user’s name and database:

{ usersInfo: { user: <name>, db: <db> } }

Alternatively, for a user that exists on the same database where the command runs, you can specify the user by its name only.

{ usersInfo: <name> }

Specify Multiple Users

In the usersInfo field, specify an array of documents:

{ usersInfo: [ { user: <name>, db: <db> },  { user: <name>, db: <db> }, ... ] }

Specify All Users for a Database

In the usersInfo field, specify 1:

{ usersInfo: 1 }

Examples

View Specific Users

To see information and privileges, but not the credentials, for the user``”Kari”`` defined in "home" database, run the following command:

db.runCommand(
               {
                 usersInfo:  { user: "Kari", db: "home" },
                 showPrivileges: true
               }
)

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:

db.getSiblingDB("home").runCommand(
                                    {
                                      usersInfo:  "Kari",
                                      showPrivileges: true
                                    }
)

View Multiple Users

To view info for several users, use an array, with or without the optional fields showPrivileges and showCredentials. For example:

db.runCommand( { usersInfo: [ { user: "Kari", db: "home" }, { user: "Li", db: "myApp" } ],
                 showPrivileges: true
             } )

View All Users for a Database

To view all users on the database the command is run, use a command document that resembles the following:

db.runCommand( { usersInfo: 1 } )

When viewing all users, you can specify the showCredentials field but not the showPrivileges field.