文档菜单
文档首页
/
MongoDB 手册
/ / /

connectionStatus

在本页

  • 定义
  • 兼容性
  • 语法
  • 示例
  • 输出
connectionStatus

返回关于当前连接的信息,特别是认证用户的状态和他们的可用权限。

此命令在以下环境中部署的部署中可用

  • MongoDB Atlas:MongoDB在云中的全面托管服务

注意

此命令在所有MongoDB Atlas集群中受支持。有关所有命令的Atlas支持信息,请参阅不受支持的命令。

  • MongoDB Enterprise:基于订阅的、自我管理的MongoDB版本

  • MongoDB Community:源代码可用的、免费使用和自我管理的MongoDB版本

该命令的语法如下

db.runCommand(
{
connectionStatus: 1,
showPrivileges: <boolean>
}
)

connectionStatus 支持以下可选字段

字段
类型
描述
showPrivileges
布尔型

可选。将 showPrivileges 设置为 true,以指示 connectionStatus 返回当前认证用户拥有的全部权限集合。

默认情况下,该字段为 false

要运行 connectionStatus,请使用 db.runCommand() 方法,如下所示

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

包含当前连接认证状态的文档,包括用户和可用权限。

connectionStatus.authinfo.authenticatedUsers

包含每个已认证用户文档的数组。

connectionStatus.authInfo.authenticatedUsers[n].user

用户名称。

connectionStatus.authInfo.authenticatedUsers[n].db

与用户凭证关联的数据库。

connectionStatus.authinfo.authenticatedUserRoles

包含分配给当前连接的每个角色的文档数组。

connectionStatus.authinfo.authenticatedUserRoles[n].role

当前认证用户关联的当前角色的定义。有关更多信息,请参阅自托管部署中的内置角色自托管部署的权限操作

connectionStatus.authinfo.authenticatedUserRoles[n].db

应用role的数据库。

connectionStatus.authInfo.authenticatedUserPrivileges

一个数组,包含描述当前连接所授予的操作的文档,按资源分组。

connectionStatus.authInfo.authenticatedUserPrivileges[n].resource

一个描述connectionStatus.authInfo.authenticatedUserPrivileges[n].actions应用的数据库和(如果适用)集合的文档。

connectionStatus.authInfo.authenticatedUserPrivileges[n].actions

列出连接可访问的指定资源的权限动作的数组。

connectionStatus.ok

命令的返回值。值为 1 表示成功。

返回

connPoolStats