killOp
定义
killOp
终止操作 ID 所指定的操作。
mongosh
provides thedb.killOp()
helper. To find operations and their corresponding IDs, see$currentOp
ordb.currentOp()
.The
killOp
command must be run against theadmin
database.To run killOp, use the
db.runCommand( { <command> } )
method.
兼容性
此命令可用于以下环境中托管的部署:
MongoDB Atlas:用于云中 MongoDB 部署的完全托管服务
重要
此命令在 M0、M2、M5、M10+ 和 Flex 集群中提供有限支持。有关更多信息,请参阅不支持的命令。
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
语法
该命令采用以下形式:
db.adminCommand( { killOp: 1, op: <opid>, comment: <any> } )
命令字段
Parameter | 类型 | 说明 |
---|---|---|
| 数字 | 操作 ID。 |
| any | 可选。用户提供的待附加到该命令的注释。设置后,该注释将与该命令的记录一起出现在以下位置:
注释可以是任何有效的 BSON 类型(字符串、整型、对象、数组等)。 |
警告
终止正在运行的操作时要格外小心。仅使用 killOp
来终止客户端发起的操作,而不会终止数据库内部操作。
行为
Do not use killOp
to terminate an in-progress index
builds in replica sets or sharded clusters. Use dropIndexes
on the 主节点 to drop the index. See
停止进行中的索引构建.
访问控制
在使用authorization
运行的系统上,要终止不属于用户的操作,用户必须具有包括killop
特权操作的访问权限。
分片集群
The killOp
command can be run on
a mongos
and can kill queries (i.e. read operations)
that span shards in a cluster. The killOp
command from the
mongos
does not propagate to the shards when the
operation to be killed is a write operation.
For information on how to list sharding operations that are active on a
mongos
, see the localOps
parameter in
$currentOp
.
For more information and examples on killing operations on a sharded cluster, see:
例子
The following example uses killOp
to target
the running operation with opid 3478
.
db.adminCommand( { "killOp": 1, "op": 3478 } )
操作返回以下结果:
{ "info" : "attempting to kill op", "ok" : 1 }
killOp
reports success if it succeeded in marking the
specified operation for termination. Operations may not actually be
terminated until they reach an appropriate interruption point. Use
$currentOp
or db.currentOp()
to confirm the
target operation was terminated.