3.2 新版功能.



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:

{ "killOp": 1, "op": <opid> }
Parameter Type Description
op number An operation ID.


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

在 4.0 版更改: The killOp command can be run on a mongos and can kill queries that span shards in a cluster. For information on how to list sharding operations that are active on a mongos, see the localOps parameter in $currentOp.

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.

在 3.2.9 版更改: On mongod instances, users can kill their own operations even without the killop privilege action.


The following example uses killOp to target the 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 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.