Definition
connectionStatusReturns information about the current connection, specifically the state of authenticated users and their available permissions.
Compatibility
This command is available in deployments hosted in the following environments:
- MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
Note
This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.
- MongoDB Enterprise: The subscription-based, self-managed version of MongoDB
- MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB
Syntax
The command has the following syntax:
db.runCommand(
{
connectionStatus: 1,
showPrivileges: <boolean>
}
)Command Fields
connectionStatus supports the following optional field:
| Field | Type | Description |
|---|---|---|
| boolean | Optional. Set By default, this field is |
Example
To run connectionStatus use the db.runCommand() method, as in the following:
db.runCommand( { connectionStatus: 1, showPrivileges: true } )Output
connectionStatus.authInfoA document with data about the authentication state of the current connection, including users and available permissions.
connectionStatus.authinfo.authenticatedUsersAn array with documents for each authenticated user.
connectionStatus.authInfo.authenticatedUsers[n].userThe user's name.
connectionStatus.authInfo.authenticatedUsers[n].dbThe database associated with the user's credentials.
connectionStatus.authinfo.authenticatedUserRolesAn array with documents for each role granted to the current connection:
connectionStatus.authinfo.authenticatedUserRoles[n].roleThe definition of the current roles associated with the current authenticated users. See Built-In Roles and Privilege Actions for more information.
connectionStatus.authinfo.authenticatedUserRoles[n].dbThe database to which
roleapplies.
connectionStatus.authInfo.authenticatedUserPrivilegesAn array with documents describing the actions granted to the current connection, grouped by resource.
connectionStatus.authInfo.authenticatedUserPrivileges[n].resourceA document describing the database and, if applicable, collection to which
connectionStatus.authInfo.authenticatedUserPrivileges[n].actionsapplies.
connectionStatus.authInfo.authenticatedUserPrivileges[n].actionsAn array listing the privilege actions that the connection has access to for the specified resource.
connectionStatus.authInfo.UUIDThe UUID of the current connected client.
connectionStatus.okThe return value for the command. A value of
1indicates success.