Docs 菜单
Docs 主页
/
MongoDB Manual
/ / /

killCursors

在此页面上

  • 定义
  • 语法
  • 命令字段
  • 必需的访问权限
  • killCursors 和事务
  • 例子
killCursors

终止集合的一个或多个指定游标。 MongoDB 驱动程序使用 killCursors命令作为客户端游标实现的一部分。

注意

一般来说,应用程序不应直接使用killCursors命令。

必须针对要终止其游标的集合的数据库运行killCursors命令。

要运行 killCursors,请使用db.runCommand( { <command> } )方法。

该命令具有以下语法:

db.runCommand(
{
killCursors: <collection>,
cursors: [ <cursor id1>, ... ], comment: <any>
}
)

该命令接受以下字段:

字段
类型
说明
killCursors
字符串
集合的名称。
cursors
阵列
要终止的游标的 ID。
comment
注意到

可选。用户提供的待附加到该命令的注释。设置后,该注释将与该命令的记录一起出现在以下位置:

注释可以是任何有效的 BSON 类型(字符串、整型、对象、数组等)。

无论用户是否具有killCursors的特权,用户始终可以终止自己的游标。创建游标时,游标与用户相关联。

如果用户拥有killAnyCursor权限,则该用户可以终止任何游标,甚至是其他用户创建的游标。

您不能将killCursors指定为事务中的第一个操作。

考虑对collection执行以下find test.restaurants操作:

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
}
← getParameter
killOp →