$listSessions
On this page本页内容
Definition定义
$listSessions
-
Lists all sessions stored in the列出存储在配置数据库的system.sessions
collection in theconfig
database.system.sessions
集合中的所有会话。These sessions are visible to all members of the MongoDB deployment.MongoDB部署的所有成员都可以看到这些会话。ImportantWhen a user creates a session on a当用户在mongod
ormongos
instance, the record of the session initially exists only in-memory on the instance; i.e. the record is local to the instance.mongod
或mongos
实例上创建会话时,会话的记录最初只存在于实例的内存中;即,该记录是实例的本地记录。Periodically, the instance will sync its cached sessions to the实例将定期将其缓存的会话同步到配置数据库中的system.sessions
collection in theconfig
database, at which time, they are visible to$listSessions
and all members of the deployment.system.sessions
集合,此时$listSessions
和部署的所有成员都可以看到这些会话。Until the session record exists in the在system.sessions
collection, you can only list the session via the$listLocalSessions
operation.system.sessions
集合中存在会话记录之前,只能通过$listLocalSessions
操作列出会话。To run要运行$listSessions
, it must be the first stage in the pipeline.$listSessions
,它必须是管道中的第一个阶段。The stage has the following syntax:该阶段具有以下语法:{ $listSessions: <document> }
The$listSessions
stage takes a document with one of the following contents:$listSessions
阶段接收具有以下内容之一的文档:Field字段Description描述{ }
If running with access control, returns all sessions for the current authenticated user.如果使用访问控制运行,则返回当前已验证用户的所有会话。
If running without access control, returns all sessions.如果在没有访问控制的情况下运行,则返回所有会话。{ users: [ { user: <user>, db: <db> }, ... ] }
Returns all sessions for the specified users.返回指定用户的所有会话。If running with access control, the authenticated user must have privileges with如果使用访问控制运行,则经过身份验证的用户必须具有在群集上执行listSessions
action on the cluster to list sessions for other users.listSessions
操作的权限,才能列出其他用户的会话。{ allUsers: true }
Returns all sessions for all users.返回所有用户的所有会话。If running with access control, the authenticated user must have privileges with如果使用访问控制运行,则经过身份验证的用户必须具有在群集上执行listSessions
action on the cluster.listSessions
操作的权限。
Restrictions限制
事务中不允许$listSessions
is not allowed in transactions.$listSessions
Examples实例
List All Sessions列出所有会话
From the 在system.sessions
collection, the following aggregation operation lists all sessions:system.sessions
集合中,以下聚合操作列出了所有会话:
If running with access control, the current user must have privileges with 如果使用访问控制运行,则当前用户必须具有在群集上执行listSessions
action on the cluster.listSessions
操作的权限。
use config
db.system.sessions.aggregate( [ { $listSessions: { allUsers: true } } ] )
List All Sessions for the Specified Users列出指定用户的所有会话
From the 在system.sessions
collection, the following aggregation operation lists all sessions for the specified user myAppReader@test
:system.sessions
集合中,以下聚合操作列出指定用户的所有会话myAppReader@test
:
If running with access control and the current user is not the specified user, the current user must have privileges with 如果使用访问控制运行,并且当前用户不是指定的用户,则当前用户必须具有在群集上执行listSessions
action on the cluster.listSessions
操作的权限。
use config
db.system.sessions.aggregate( [ { $listSessions: { users: [ {user: "myAppReader", db: "test" } ] } } ] )
List All Sessions for the Current User列出当前用户的所有会话
From the 在system.sessions
collection, the following aggregation operation lists all sessions for the current user if run with access control:system.sessions
集合中,如果使用访问控制运行,以下聚合操作将列出当前用户的所有会话:
use config
db.system.sessions.aggregate( [ { $listSessions: { } } ] )
If run without access control, the operation lists all sessions.如果在没有访问控制的情况下运行,该操作将列出所有会话。