AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
Docs Menu

$listLocalSessions(集計ステージ)

$listLocalSessions

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. 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.

The $listLocalSessions operation uses the db.aggregate() method and not the db.collection.aggregate().

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

このステージの構文は、次のとおりです。

{ $listLocalSessions: <document> }

The $listLocalSessions stage takes a document with one of the following contents:

フィールド
説明

{ }

アクセス制御を使用して実行している場合、 は現在認証されているユーザーのすべてのセッションを返します。

アクセス制御なしで実行している場合、 はすべてのセッションを返します。

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

指定されたユーザーのすべてのセッションを返します。 アクセス制御を使用して実行中の場合、認証されたユーザーは、他のユーザーのセッションを一覧表示するには、クラスターに対してlistSessionsアクションの特権を持っている必要があります。

{ allUsers: true }

すべてのユーザーのすべてのセッションを返します。 アクセス制御を使用して実行している場合、認証されたユーザーにはクラスターでのlistSessionsアクション権限が必要です。

$listLocalSessions トランザクションでは許可されていません。

接続されたmongod / mongosインスタンスのメモリ内セッション キャッシュから、次の集計操作はすべてのセッションを一覧表示します。

注意

アクセス制御を使用して実行中の場合、現在のユーザーにはクラスターに対するlistSessionsアクションの特権が必要です。

db.aggregate( [ { $listLocalSessions: { allUsers: true } } ] )

接続された mongod または mongos インスタンスのメモリ内キャッシュから、次の集計操作は、指定されたユーザー myAppReader@test のすべてのセッションを一覧表示します。

注意

アクセス制御を使用して実行中で、現在のユーザーが指定されたユーザーでない場合、現在のユーザーにはクラスターに対するlistSessionsアクションの権限が必要です。

db.aggregate( [ { $listLocalSessions: { users: [ { user: "myAppReader", db: "test" } ] } } ] )

接続されたmongod / mongosインスタンスのメモリ内キャッシュから、次の集計操作は、アクセス制御を使用して実行された場合、現在のユーザーのすべてのセッションを一覧表示します。

db.aggregate( [ { $listLocalSessions: { } } ] )

アクセス制御なしで実行すると、操作にはすべてのローカル セッションが一覧表示されます。

MongoDB Node.jsドライバーを使用して $listLocalSessions ステージを集計パイプラインに追加するには、パイプラインオブジェクトで $listLocalSessions 演算子を使用します。

次の集計操作は、すべてのローカル セッションを一覧表示します。

const pipeline = [{ $listLocalSessions: { allUsers: true } }];
const cursor = db.aggregate(pipeline);
return cursor;

注意

アクセス制御を使用して実行中の場合、現在のユーザーにはクラスターに対するlistSessionsアクションの特権が必要です。

次の集計操作では、指定されたユーザー myAppReader@test のすべてのセッションが一覧表示されます。

const pipeline = [
{
$listLocalSessions: {
users: [{ user: "myAppReader", db: "test"}]
}
}
];
const cursor = db.aggregate(pipeline);
return cursor;

注意

アクセス制御を使用して実行中で、現在のユーザーが指定されたユーザーでない場合、現在のユーザーにはクラスターに対するlistSessionsアクションの権限が必要です。

アクセス制御を使用して実行すると、次の集計操作には現在のユーザーのすべてのセッションが一覧表示されます。

const pipeline = [{ $listLocalSessions: {} }];
const cursor = db.aggregate(pipeline);
return cursor;

アクセス制御なしで実行すると、操作にはすべてのローカル セッションが一覧表示されます。

$listLocalSessions メモリにキャッシュされたセッションごとに 1 つのドキュメントを含むカーソルを返します。各ドキュメントには次のプロトタイプがあります。

{
_id: {
id: <UUID>,
uid: <BinData>
},
lastUse: <date>
}
フィールド
タイプ
説明

_id.id

UUID

セッションの全域一意の識別子 (UUID)。

_id.uid

BinData

セッションに関連付けられた認証されたユーザーの認証情報のハッシュ。

lastUse

date

セッションが最後に使用された日時。

このページを評価