Viewing and Terminating Current Operation

View Operation(s) in Progress

> db.currentOp();
{ inprog: [ { "opid" : 18 , "op" : "query" , "ns" : "mydb.votes" ,
              "query" : "{ score : 1.0 }" , "inLock" : 1 }
          ]
}
>
> // to include idle connections in report:
> db.currentOp(true);

Fields:

  • opid - an incrementing operation number.  Use with killOp().
  • active - if the operation is active, false if the operation is queued
  • waitingForLock - if true, lock has been requested but not yet granted
  • op - the operation type (query, update, etc.)
  • ns - namespace for the operation (database + collection name) (Note: if the ns begins with a question mark, the operation has yielded.)
  • query - the query spec, if operation is a query
  • lockType - the type of lock the operation requires, either read or write or none. See concurrency page.
  • client - address of the client who requested the operation
  • desc - the type of connection. conn indicates a normal client connections. Other values indicate internal threads in the server.
  • threadId - id of the thread
  • numYields - the number of the times the operation has yielded (to some other operation)

From a driver one runs currentOp by executing the equivalent of:

db.$cmd.sys.inprog.find()

Killing an In Progress Operation

v1.4+

> db.killOp(1234/*opid*/)
> // same as: db.$cmd.sys.killop.findOne({op:1234})
Be careful about terminating internal operations, for example the a replication sync thread. Typically you only kill operations from external clients.

Sharded Databases

In a sharded environment, operations named "writebacklistener" will appear. These are long-lived socket connections between mongos and mongod. These can be ignored. See Sharding FAQ.

See Also


Labels

commands commands Delete
terminate terminate Delete
currentop currentop Delete
command command Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

PLEASE POST QUESTIONS IN THE USER GROUPS FORUM. Post non-question comments and helpful hints here.

blog comments powered by Disqus