Database Manual / Reference / Database Commands / Diagnostics

connectionStatus (database command数据库命令)

Definition定义

connectionStatus
Returns 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:云中MongoDB部署的完全托管服务

Note

This command is supported in all MongoDB Atlas clusters. 所有MongoDB Atlas集群都支持此命令。For information on Atlas support for all commands, see Unsupported Commands.有关Atlas支持所有命令的信息,请参阅不支持的命令

  • MongoDB Enterprise: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本
  • MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB: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描述
showPrivilegesboolean布尔值

Optional. 可选。Set showPrivileges to true to instruct connectionStatus to return the full set of privileges that currently-authenticated users possess.showPrivileges设置为true,以指示connectionStatus返回当前经过身份验证的用户所拥有的全部权限

By default, this field is false.默认情况下,此字段为false

Example示例

To run connectionStatus use the db.runCommand() method, as in the following:要运行connectionStatus,请使用db.runCommand()方法,如下所示:

db.runCommand( { connectionStatus: 1, showPrivileges: true } )

Output输出

connectionStatus.authInfo
A document with data about the authentication state of the current connection, including users and available permissions.包含当前连接身份验证状态数据的文档,包括用户和可用权限。
connectionStatus.authinfo.authenticatedUsers

An array with documents for each authenticated user.一个数组,其中包含每个经过身份验证的用户的文档。

connectionStatus.authInfo.authenticatedUsers[n].user
The user's name.用户名。
connectionStatus.authInfo.authenticatedUsers[n].db
The database associated with the user's credentials.与用户凭据关联的数据库。
connectionStatus.authinfo.authenticatedUserRoles

An array with documents for each role granted to the current connection:一个数组,其中包含授予当前连接的每个角色的文档:

connectionStatus.authinfo.authenticatedUserRoles[n].role
The 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].db
The database to which role applies.应用role的数据库。
connectionStatus.authInfo.authenticatedUserPrivileges

An array with documents describing the actions granted to the current connection, grouped by resource.一个数组,其中包含描述授予当前连接的操作的文档,按资源分组。

connectionStatus.authInfo.authenticatedUserPrivileges[n].resource
A document describing the database and, if applicable, collection to which connectionStatus.authInfo.authenticatedUserPrivileges[n].actions applies.描述数据库以及connectionStatus.authInfo.authenticatedUserPrivileges[n].actions所应用的集合(如果适用)的文档。
connectionStatus.authInfo.authenticatedUserPrivileges[n].actions
An array listing the privilege actions that the connection has access to for the specified resource.列出连接对指定资源有权访问的权限操作的数组。
connectionStatus.authInfo.UUID
The UUID of the current connected client.当前连接的客户端的UUID。
connectionStatus.ok
The return value for the command. A value of 1 indicates success.命令的返回值。值为1表示成功。