Docs Menu

$listSessions

이 페이지의 내용

$listSessions

Lists all sessions stored in the system.sessions collection in the config database. These sessions are visible to all members of the MongoDB deployment.

중요

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. 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. Until the session record exists in the system.sessions collection, you can only list the session via the $listLocalSessions operation.

To run $listSessions, it must be the first stage in the pipeline.

이 단계에는 다음 구문이 있습니다.

{ $listSessions: <document> }

$listSessions 단계는 다음 내용 중 하나가 포함된 문서를 사용합니다.

필드
설명

{ }

액세스 제어와 함께 실행하는 경우 현재 인증된 사용자에 대한 모든 세션을 반환합니다.

액세스 제어 없이 실행하는 경우 모든 세션을 반환합니다.

{ users: [ { user: <user>, db: <db> }, ... ] }

지정된 사용자에 대한 모든 세션을 반환합니다. 액세스 제어와 함께 실행하는 경우 인증된 사용자는 cluster에서 listSessions 조치가 있는 권한이 있어야 다른 사용자의 세션을 나열할 수 있습니다.

{ allUsers: true }

모든 사용자에 대한 모든 세션을 반환합니다. 액세스 제어와 함께 실행하는 경우 인증된 사용자는 클러스터에서 listSessions 작업이 있는 권한이 있어야 합니다.

트랜잭션에는 $listSessions이 허용되지 않습니다.

From the system.sessions collection, the following aggregation operation lists all sessions:

참고

액세스 제어를 사용하여 실행하는 경우 현재 사용자는 cluster에 대해 listSessions 조치가 있는 권한이 있어야 합니다.

use config
db.system.sessions.aggregate( [ { $listSessions: { allUsers: true } } ] )

From the system.sessions collection, the following aggregation operation lists all sessions for the specified user myAppReader@test:

참고

액세스 제어와 함께 실행 중이고 현재 사용자가 지정된 사용자가 아닌 경우 현재 사용자에게 cluster에 대한 listSessions 조치가 있는 권한이 있어야 합니다.

use config
db.system.sessions.aggregate( [ { $listSessions: { users: [ {user: "myAppReader", db: "test" } ] } } ] )

From the system.sessions collection, the following aggregation operation lists all sessions for the current user if run with access control:

use config
db.system.sessions.aggregate( [ { $listSessions: { } } ] )

If run 미포함: access control, the operation lists all sessions.

이 페이지의 내용