On this page
killCursors
在本页面
3.2 版中的新功能。
Definition
killCursors
- 杀死一个或多个指定集合的游标。 MongoDB 驱动程序将killCursors命令用作 Client 端游标实现的一部分。
Note
通常,应用程序不应直接使用killCursors命令。
必须针对要杀死其光标的集合的数据库运行killCursors
命令。
要运行 killCursors,请使用db.runCommand( { <command> })方法。
该命令具有以下形式:
db.runCommand( { "killCursors": <collection>, "cursors": [ <cursor id1>, ... ] } )
Field | Type | Description |
---|---|---|
killCursors |
string | 集合的名称。 |
cursors |
array | 要杀死的游标 ID。 |
Required Access
在版本 3.6.3 中更改。
要成功执行killCursors命令,您希望杀死的所有游标都必须与当前经过身份验证的用户关联。 MongoDB 将游标与创建游标时已通过身份验证的用户相关联。如果由于权限问题操作失败,该命令将返回错误消息。
或者,如果用户拥有killAnyCursor特权,则该用户可以杀死任何光标,无论该光标与哪个用户关联。
Example
考虑对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" : 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
}
要终止此光标,请使用killCursors命令。
use test
db.runCommand( { killCursors: "restaurants", cursors: [ NumberLong("18314637080") ] } )
killCursors返回以下操作详细信息:
{
"cursorsKilled" : [
NumberLong("18314637080")
],
"cursorsNotFound" : [ ],
"cursorsAlive" : [ ],
"cursorsUnknown" : [ ],
"ok" : 1
}