Docs 主页 → 开发应用程序 → MongoDB Manual
connectionStatus
定义
connectionStatus
返回有关当前连接的信息,具体指已验证用户的状态及其可用权限。
{ connectionStatus: 1, showPrivileges: <boolean> } connectionStatus
支持以下可选字段:字段类型说明showPrivileges
布尔可选。将
showPrivileges
设置为 true,以指示connectionStatus
返回当前经过身份验证的用户拥有的完整权限集。默认情况下,此字段为
false
。
例子
要运行connectionStatus
,请使用db.runCommand()
方法,如下所示:
db.runCommand( { connectionStatus: 1, showPrivileges: true } )
输出
connectionStatus.authinfo.authenticatedUserRoles
一个数组,其中包含授予当前连接的每个角色的文档:
connectionStatus.authinfo.authenticatedUserRoles[n].db
应用
role
的数据库。
connectionStatus.authInfo.authenticatedUserPrivileges
一个数组,其中包含描述授予当前连接的动作的文档,按资源分组。
connectionStatus.authInfo.authenticatedUserPrivileges[n].resource
描述数据库以及适用
connectionStatus.authInfo.authenticatedUserPrivileges[n].actions
的集合(如适用)的文档。