Docs 菜单

killOp

killOp

终止操作 ID 所指定的操作。 mongosh provides the db.killOp() helper. To find operations and their corresponding IDs, see $currentOp or db.currentOp().

The killOp command must be run against the admin database.

To run killOp, use the db.runCommand( { <command> } ) method.

此命令可用于以下环境中托管的部署:

重要

此命令在 M0、M2、M5、M10+ 和 Flex 集群中提供有限支持。有关更多信息,请参阅不支持的命令。

该命令采用以下形式:

db.adminCommand(
{
killOp: 1,
op: <opid>,
comment: <any>
}
)
Parameter
类型
说明

op

数字

操作 ID。

comment

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特权操作的访问权限。

mongod实例上,即使没有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.