killOp

On this page本页内容

Definition定义

killOp

Terminates an operation as specified by the operation ID. 根据操作ID指定终止操作。mongosh provides the db.killOp() helper. 提供db.killOp()帮助器。To find operations and their corresponding IDs, see $currentOp or db.currentOp().要查找操作及其对应的ID,请参阅$currentOpdb.currentOp()

The killOp command must be run against the admin database.killOp命令必须针对admin数据库运行。

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

The command has the following form:命令的格式如下:

{ "killOp": 1, "op": <opid>, comment: <any> }
Parameter参数Type类型Description描述
opnumberAn operation ID.操作ID。
commentany

Optional. 可选。A user-provided comment to attach to this command. 用户提供了附加到此命令的注释。Once set, this comment appears alongside records of this command in the following locations:设置后,此注释将与此命令的记录一起显示在以下位置:

A comment can be any valid BSON type(string, integer, object, array, etc).注释可以是任何有效的BSON类型(字符串、整数、对象、数组等)。

New in version 4.4.在版本4.4中新增

Warning警告

Terminate running operations with extreme caution. 极端小心地终止运行操作。Only use killOp to terminate operations initiated by clients and do not terminate internal database operations.仅使用killOp终止客户端启动的操作,而不终止内部数据库操作。

Behavior行为

Do not use killOp to terminate an in-progress index builds in replica sets or sharded clusters. 不要使用killOp终止副本集或分片集群中正在进行的索引构建。Use dropIndexes on the primary to drop the index. primary节点上使用dropIndexes来删除索引。See Stop In-Progress Index Builds.请参阅停止进行中的索引生成

Access Control访问控制

On systems running with authorization, to kill operations not owned by the user, the user must have access that includes the killop privilege action.authorization运行的系统上,要终止不属于用户的操作,用户必须具有包括killop权限操作在内的访问权限。

Changed in version 3.2.9.在版本3.2.9中更改

On mongod instances, users can kill their own operations even without the killop privilege action.mongod实例上,即使没有killop权限操作,用户也可以终止自己的操作。

Sharded Cluster分片群集

Starting in MongoDB 4.0, the killOp command can be run on a mongos and can kill queries (i.e. read operations) that span shards in a cluster. 从MongoDB 4.0开始,killOp命令可以在mongos上运行,并可以终止跨越集群中分片的查询(即读取操作)。The killOp command from the mongos does not propagate to the shards when the operation to be killed is a write operation.当要终止的操作是写操作时,mongoskillop命令不会传播到分片。

For information on how to list sharding operations that are active on a mongos, see the localOps parameter in $currentOp.有关如何列出mongos上活动的分片操作的信息,请参阅$currentOp中的localOps参数。

For more information and examples on killing operations on a sharded cluster, see:有关在分片化集群上终止操作的更多信息和示例,请参阅:

Example示例

The following example uses killOp to target the running operation with opid 3478.下面的示例使用killOp以opid 3478的运行操作为目标。

db.adminCommand( { "killOp": 1, "op": 3478 } )

The operation returns the following result:该操作返回以下结果:

{ "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.使用$currentOpdb.currentOp()确认目标操作已终止。

←  killCursorslistCollections →