对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

killOp(数据库命令)

killOp

Terminates an operation as specified by the operation ID. mongosh provides the db.killOp() helper. To find operations and their corresponding IDs, see $currentOp or db.currentOp().

killOp命令必须针对admin数据库运行。

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

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

  • MongoDB Atlas:用于云中 MongoDB 部署的完全托管服务

重要

所有MongoDB Atlas集群都对该命令提供有限支持。有关更多信息,请参阅不支持的命令。

该命令采用以下形式:

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

op

数字

操作 ID。

comment

any

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

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

警告

Terminate running operations with extreme caution. Only use killOp to terminate operations initiated by clients and do not terminate internal database operations.

Do not use killOp to terminate an in-progress index builds in replica sets or sharded clusters. Use dropIndexes on the primary to drop the index. See Stop In-Progress Index Builds.

在使用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.

有关如何列出 mongos 上活动的分片操作的信息,请参阅 $currentOp 中的 localOps 参数。

有关针对分片集群的终止操作的更多信息和示例,请参阅:

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.