定義
killAllSessionsThe
killAllSessionscommand kills all sessions for the specified users. [1]
構文
このコマンドの構文は、次のとおりです。
db.runCommand( { killAllSessions: [ { user: <user>, db: <dbname> }, ... ] } )
互換性
このコマンドは、次の環境でホストされている配置で使用できます。
MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン
MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン
重要
This command is not supported in MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.
コマンドフィールド
The command takes an array of documents where each document specifies the user and the user's authentication database. Specify an empty array to kill all sessions for all users in the system. [1]
既存のセッションを表示
既存のセッションを表示するには、 $listSessions操作 または$listLocalSessionsを参照してください。
| [1] | (1, 2) The killAllSessions operation ignores sessions that have transactions in prepared state. See Behavior for details. |
アクセス制御
If the deployment enforces authentication/authorization, you must have the killAnySession to run the killAllSessions command.
注意
ユーザーはkillAnySession特権アクションがなくても自分のセッションを強制終了できます。
動作
進行中の操作
セッションを強制終了すると、セッション内で進行中の操作がすべて終了され、これらの操作に関連付けられている開いているカーソルが閉じられます。
強制終了されたセッションの可用性
強制終了されたセッションは引き続き現在のセッションとして表示され、今後の操作では強制終了されたセッションが使用される可能性があります。 既存のセッションを表示するには、 $listSessions操作 または$listLocalSessionsを参照してください。
トランザクションが準備済み状態のセッション
The killAllSessions operation ignores sessions that have Transactions in prepared state. Transactions in prepared state refer to transactions with write operations that span multiple shards whose commit coordinator has completed the "sendingPrepare" action.
例
すべてのセッションを強制終了
次の操作は、システム内のすべてのユーザーのすべてのセッションを強制終了します。
db.runCommand( { killAllSessions: [ ] } )
特定のユーザーのすべてのセッションを強制終了
次の操作は、 データベース内のユーザーappReader db1とreportWriter データベース内のユーザーdb2 のすべてのセッションを強制終了します。
db.runCommand( { killAllSessions: [ { user: "appReader", db: "db1" }, { user: "reportWriter", db: "db2" } ] } )