On this page本页内容
New in version 3.2.版本3.2中的新功能。
killOp
¶Terminates an operation as specified by the operation ID. The mongo
shell 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.
The command has the following form:
op |
number | An operation ID. |
comment |
any |
A comment can be any valid BSON type (string, integer, object, array, etc).
|
Warning
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 Abort In-Progress Index Builds.
On systems running with authorization
, to kill operations not owned by the user, the user must have access that includes the killop
privilege action.
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. 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
.
The operation returns the following result:操作返回以下结果:
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.