killOp
New in version 3.2.
Definition
killOp
- Terminates an operation as specified by the operation ID.The
mongo
shell provides thedb.killOp()
helper.To find operations and their corresponding IDs,see$currentOp
ordb.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:
- { "killOp": 1, "op": <opid> }
ParameterTypeDescriptionop
numberAn operation ID.
Warning
Terminate running operations with extreme caution. Only usekillOp
to terminate operations initiated by clientsand do not terminate internal database operations.
Access Control
On systems running with authorization
, to killoperations not owned by the user, the user must have access thatincludes the killop
privilege action.
Changed in version 3.2.9: On mongod
instances, users can kill their own operationseven without the killop
privilege action.
Sharded Cluster
Starting in MongoDB 4.0, the killOp
command can be run ona mongos
and can kill queries (i.e. read operations)that span shards in a cluster. The killOp
command from themongos
does not propagate to the shards when theoperation to be killed is a write operation.
For information on how to list sharding operations that are active on amongos
, see the localOps
parameter in$currentOp
.
For more information and examples on killing operations on a shardedcluster, see:
Example
The following example uses killOp
to targetthe running operation with 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 thespecified operation for termination. Operations may not actually beterminated until they reach an appropriate interruption point. Use$currentOp
or db.currentOp()
to confirm thetarget operation was terminated.