On this page本页内容
killCursors
Kills the specified cursor or cursors for a collection. 杀死集合的指定游标。MongoDB drivers use the MongoDB驱动程序使用killCursors
command as part of the client-side cursor implementation.killCursors
命令作为客户端游标实现的一部分。
In general, applications should not use the 通常,应用程序不应直接使用killCursors
command directly.killCursors
命令。
The killCursors
command must be run against the database of the collection whose cursors you wish to kill.killCursors
命令必须针对要删除其游标的集合的数据库运行。
To run killCursors, use the 要运行killCursors,请使用db.runCommand( { <command> } )
method.db.runCommand( { <command> } )
方法。
The command has the following form:命令的格式如下:
db.runCommand( { "killCursors": <collection>, "cursors": [ <cursor id1>, ... ], comment: <any> } )
killCursors | string | |
cursors | array | |
comment | any |
|
killCursors
. killCursors
,用户都可以杀死自己的游标。killCursors
privilege to kill their own cursors. killCursors
权限才能杀死自己的游标。If a user possesses the 如果用户拥有killAnyCursor
privilege, that user may kill any cursor, even cursors created by other users.killAnyCursor
权限,则该用户可以杀死任何游标,甚至是其他用户创建的游标。
killCursors
Starting in MongoDB 4.2, you cannot specify 从MongoDB 4.2开始,不能将killCursors
as the first operation in a transaction.killCursors
指定为事务中的第一个操作。
Consider the following 考虑对find
operation on the test.restaurants
collection:test.restaurants
集合执行以下find
操作:
use test db.runCommand( { find: "restaurants", filter: { stars: 5 }, projection: { name: 1, rating: 1, address: 1 }, sort: { name: 1 }, batchSize: 5 } )
which returns the following:其返回以下内容:
{ "waitedMS" : NumberLong(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" : NumberLong("18314637080"), "ns" : "test.restaurants" }, "ok" : 1 }
To kill this cursor, use the 要终止此游标,请使用killCursors
command.killCursors
命令。
use test db.runCommand( { killCursors: "restaurants", cursors: [ NumberLong("18314637080") ] } )
killCursors
returns the following operation details:返回以下操作详细信息:
{ "cursorsKilled" : [ NumberLong("18314637080") ], "cursorsNotFound" : [ ], "cursorsAlive" : [ ], "cursorsUnknown" : [ ], "ok" : 1 }