On this page本页内容
$listLocalSessions
Lists the sessions cached in memory by the 列出mongod
or mongos
instance.mongod
或mongos
实例缓存在内存中的会话。
When a user creates a session on a 当用户在mongod
or mongos
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 the config
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
操作列出会话。
The $listLocalSessions
operation uses the db.aggregate()
method and not the db.collection.aggregate()
.$listLocalSessions
操作使用db.aggregate()
方法,而不是db.collection.aggregate()
。
To run 要运行$listLocalSessions
, it must be the first stage in the pipeline.$listLocalSessions
,它必须是管道中的第一个阶段。
The stage has the following syntax:该阶段语法如下:
{ $listLocalSessions: <document> }
The $listLocalSessions
stage takes a document with one of the following contents:$listLocalSessions
阶段接受具有以下内容之一的文档:
{ } |
|
{ users: [ { user: <user>, db: <db> }, ... ] } | listSessions action on the cluster to list sessions for other users.listSessions 操作的权限,才能列出其他用户的会话。
|
{ allUsers: true } | listSessions action on the cluster.listSessions 操作的权限。
|
事务中不允许使用$listLocalSessions
is not allowed in transactions.$listLocalSessions
。
From the connected 从连接的mongod
/mongos
instance's in-memory cache of sessions, the following aggregation operation lists all sessions:mongod
/mongos
实例的会话内存缓存中,以下聚合操作列出了所有会话:
If running with access control, the current user must have privileges with 如果使用访问控制运行,则当前用户必须具有集群上listSessions
action on the cluster.listSessions
操作的权限。
db.aggregate( [ { $listLocalSessions: { allUsers: true } } ] )
From the connected 从连接的mongod
/mongos
instance's in-memory cache, the following aggregation operation lists all the sessions for the specified user myAppReader@test
:mongod
/mongos
实例的内存缓存中,以下聚合操作列出了指定用户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
操作的权限。
db.aggregate( [ { $listLocalSessions: { users: [ { user: "myAppReader", db: "test" } ] } } ] )
From the connected 从连接的mongod
/mongos
instance's in-memory cache, the following aggregation operation lists all sessions for the current user if run with access control:mongod
/mongos
实例的内存缓存中,以下聚合操作列出了当前用户的所有会话(如果使用访问控制运行):
db.aggregate( [ { $listLocalSessions: { } } ] )
If run without access control, the operation lists all local sessions.如果在没有访问控制的情况下运行,该操作将列出所有本地会话。