db.currentOp Queries in mongodb

Return active sessions running for more than x seconds:

db.currentOp().inprog.forEach(
  function(op) {
    if(op.secs_running > 5) printjson(op);
  }
)

Waiting for a lock and not a read:

db.currentOp().inprog.forEach(
   function(d){
     if(d.waitingForLock && d.lockType != "read") 
       printjson(d)
     })

Finding active writes:

db.currentOp().inprog.forEach(
   function(d){
     if(d.active && d.lockType == "write") 
       printjson(d)
     })

Finding active reads:

db.currentOp().inprog.forEach(
   function(d){
     if(d.active && d.lockType == "read") 
       printjson(d)
     })
Advertisements

3 Responses to db.currentOp Queries in mongodb

  1. tariq says:

    All the last 3 queries does not return any values. Can you have a screenshot for the results so that I an look at the results that are returned ?

    • dbamohsin says:

      Needless to say that the queries will only return results if the conditions are matched. Your active queries may be very short lived.

  2. tariq says:

    I tested it by populating 10000 rows, did export and simultaneously executed the queries but still was not able to get any results

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: