定义
killOpTerminates an operation as specified by the operation ID.
mongoshprovides thedb.killOp()helper. To find operations and their corresponding IDs, see$currentOpordb.currentOp().killOp命令必须针对admin数据库运行。要运行 killOp,请使用
db.runCommand( { <command> } )方法。
兼容性
此命令可用于以下环境中托管的部署:
- MongoDB Atlas:用于云中 MongoDB 部署的完全托管服务
重要
所有MongoDB Atlas集群都对该命令提供有限支持。有关更多信息,请参阅不支持的命令。
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
语法
该命令采用以下形式:
db.adminCommand( { killOp: 1, op: <opid>, comment: <any> } )
命令字段
Parameter | 类型 | 说明 |
|---|---|---|
| 数字 | 操作 ID。 |
| 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特权操作的访问权限。
分片集群
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.