定義
killCursorsKills the specified cursor or cursors for a collection. MongoDB drivers use the
killCursorscommand as part of the client-side cursor implementation.警告
アプリケーションは通常、
killCursorsコマンドを直接実行 しないでください 。代わりに、ドライバーにカーソル管理を自動的に処理させます。killCursorsコマンドは、強制終了するカーソルが含まれているコレクションのデータベースに対して実行する必要があります。killCursors を実行するには、
db.runCommand( { <command> } )メソッドを使用します。
互換性
このコマンドは、次の環境でホストされている配置で使用できます。
- MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
注意
This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.
MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン
MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン
構文
このコマンドの構文は、次のとおりです。
db.runCommand( { killCursors: <collection>, cursors: [ <cursor id1>, ... ], comment: <any> } )
コマンドフィールド
このコマンドは、次のフィールドを使用します。
フィールド | タイプ | 説明 |
|---|---|---|
| string | コレクションの名前。 |
| 配列 | 強制終了するカーソルの ID。 |
| any | 任意。このコマンドに添付するユーザー指定のコメント。設定すると、このコメントは以下の場所にこのコマンドの記録と合わせて表示されます。
コメントには、有効な BSON 型(string, integer, object, array など)を使用できます。 |
必要なアクセス権
独自のカーソルを強制終了
ユーザーは、killCursors 特権を持っているかどうかに関係なく、いつでも自分のカーソルを強制終了できます。カーソルは、カーソルの作成時にユーザーに関連付けられます。
任意のカーソルを強制終了
ユーザーにkillAnyCursor 特権がある場合は、任意のユーザーが作成したカーソルを強制終了できます。
killCursors およびトランザクション
You cannot specify the killCursors command as the first operation in a transaction.
さらに、トランザクション内で killCursors コマンドを実行すると、サーバーは指定されたカーソルを直ちに停止します。トランザクションがコミットされるのを待ちません。
例
test.restaurantsコレクションに対する次のfind操作を検討します。
use test db.runCommand( { find: "restaurants", filter: { stars: 5 }, projection: { name: 1, rating: 1, address: 1 }, sort: { name: 1 }, batchSize: 5 } )
により、次の結果が返されます。
{ "waitedMS" : Long(0), "cursor" : { "firstBatch" : [ { "_id" : ObjectId("57506d63f578028074723dfd"), "name" : "Cakes and more" }, { "_id" : ObjectId("57506d63f578028074723e0b"), "name" : "Pies and things" }, { "_id" : ObjectId("57506d63f578028074723e1d"), "name" : "Ice Cream Parlour" }, { "_id" : ObjectId("57506d63f578028074723e65"), "name" : "Cream Puffs" }, { "_id" : ObjectId("57506d63f578028074723e66"), "name" : "Cakes and Rolls" } ], "id" : Long("18314637080"), "ns" : "test.restaurants" }, "ok" : 1 }
To kill this cursor, use the killCursors command.
use test db.runCommand( { killCursors: "restaurants", cursors: [ Long("18314637080") ] } )
killCursors は、次の操作の詳細を返します。
{ "cursorsKilled" : [ Long("18314637080") ], "cursorsNotFound" : [ ], "cursorsAlive" : [ ], "cursorsUnknown" : [ ], "ok" : 1 }