MongoDB Monitoring: current operations

By David Mytton,
CEO & Founder of Server Density.

Published on the 14th March, 2011.

There are a number of built in tools and commands which can be used to get important information from MongoDB but because it is relatively new, it can be difficult to know what you need to be doing from an operational perspective to ensure that everything runs smoothly.

This is the last in a series of 6 posts about MongoDB monitoring based on a talk I gave at the MongoSV 2010 conference. View the series index here.

MongoDB Monitoring dashboard + alerting

We provide a MongoDB monitoring service to keep an eye on the health and performance of your MongoDB database cluster automatically and with alerting. Find out more here.

Current operations

Normally MongoDB operations will be very quick but if you have a long running query or a backlog of operations queuing up, you can use the db.currentOp() command to list every operation currently in progress. This can be used to locate long running operations and find out what is currently going on with your server.

			"opid" : "shard3:466404288",
			"active" : false,
			"waitingForLock" : false,
			"op" : "query",
			"ns" : "sd.usersEmails",
			"query" : {
			"client_s" : "",
			"desc" : "conn"

This is an example from one of our servers. It has a number of fields:

  • opid – every operation has a unique ID and if you are using sharding, shows which shard the operation is running on.
  • active – shows whether the operation is actually being run or if it’s queued.
  • waitingForLocklocking operations first request the lock and if it has yet to be granted, this will be true.
  • op – the operation type e.g. query, insert, remove.
  • ns – the namespace that is being operated on. This is usually database.collection, in this case the usersEmails collection in the sd database.
  • query – if an actual query is being executed the parameters will be displayed here.
  • client_s – the source of the operation. In this case it is a mongos on server
  • desc – conn is a normal client connection whereas other values indicate internal operations
  • secs_running – if the operation has been running for some time this will indicate how long for

Killing MongoDB operations

The most useful aspect of db.currentOp() is the opid because you can use this to kill operations. You could use this if there was a long running query which was locking up the database – be careful only to kill client operations as killing internal database operations such as replication sync can cause problems.

To kill an operation, you simply pass the opid to the db.killOp() method. For the example above, this would be:


Articles you care about. Delivered.

Help us speak your language. What is your primary tech stack?

Maybe another time