Navigation

db.currentOp()

Definition

db.currentOp()

Returns a document that contains information on in-progress operations for the database instance. The db.currentOp() method wraps the database command currentOp.

db.currentOp() has the following form:

db.currentOp(<operations>)

db.currentOp() can take the following optional argument:

Parameter Type Description
operations boolean or document

Optional. Specifies the operations to report on. Can pass either a boolean or a document.

Specify true to include operations on idle connections and system operations. Specify a document with query conditions to report only on operations that match the conditions. See Behavior for details.

Behavior

db.currentOp() can accept a filter document or a boolean parameter.

If you pass a filter document to db.currentOp(), the output returns information only for the current operations that match the filter. The filter document can contain:

Field Description
"$ownOps"

Boolean. If set to true, returns information on the current user’s operations only.

On mongod instances, users can always run db.currentOp( { "$ownOps": true } ) to view their own operations.

New in version 3.2.9.

"$all"

Boolean. If set to true, returns information on all operations, including operations on idle connections and system operations.

If the document includes "$all": true along with Output Fields conditions, only the "$all":true applies.

<filter>

Specify filter conditions on the Output Fields. See Examples.

If the document includes "$all": true along with Output Fields conditions, only the "$all": true applies.

Passing in true to db.currentOp() is equivalent to passing in a document of { "$all": true }. The following operations are equivalent:

db.currentOp(true)
db.currentOp( { "$all": true } )

db.currentOp and the database profiler report the same basic diagnostic information for all CRUD operations, including the following:

These operations are also included in the logging of slow queries (see slowOpThresholdMs for more information about slow query logging).

Access Control

On systems running with authorization, the user must have access that includes the inprog privilege action.

Changed in version 3.2.9: On mongod instances, users can run db.currentOp( { "$ownOps": true } ) to view their own operations even without the inprog privilege action.

Examples

The following examples use the db.currentOp() method with various query documents to filter the output.

Write Operations Waiting for a Lock

The following example returns information on all write operations that are waiting for a lock:

db.currentOp(
   {
     "waitingForLock" : true,
     $or: [
        { "op" : { "$in" : [ "insert", "update", "remove" ] } },
        { "query.findandmodify": { $exists: true } }
    ]
   }
)

Active Operations with no Yields

The following example returns information on all active running operations that have never yielded:

db.currentOp(
   {
     "active" : true,
     "numYields" : 0,
     "waitingForLock" : false
   }
)

Active Operations on a Specific Database

The following example returns information on all active operations for database db1 that have been running longer than 3 seconds:

db.currentOp(
   {
     "active" : true,
     "secs_running" : { "$gt" : 3 },
     "ns" : /^db1\./
   }
)

Active Indexing Operations

The following example returns information on index creation operations:

db.currentOp(
    {
      $or: [
        { op: "command", "query.createIndexes": { $exists: true } },
        { op: "none", ns: /\.system\.indexes\b/ }
      ]
    }
)

Output Example

The following is a prototype of db.currentOp() output.

{
  "inprog": [
       {
         "desc" : <string>,
         "threadId" : <string>,
         "connectionId" : <number>,
         "client" : <string>,
         "appName" : <string>,
         "opid" : <number>,
         "active" : <boolean>,
         "secs_running" : <NumberLong()>,
         "microsecs_running" : <number>,
         "op" : <string>,
         "ns" : <string>,
         "query" : <document>,
         "insert" : <document>,
         "planSummary": <string>,
         "appName" : <string>,
         "msg": <string>,
         "progress" : {
             "done" : <number>,
             "total" : <number>
         },
         "killPending" : <boolean>,
         "numYields" : <number>,
         "locks" : {
             "Global" : <string>,
             "MMAPV1Journal" : <string>,
             "Database" : <string>,
             "Collection" : <string>,
             "Metadata" : <string>,
             "oplog" : <string>
         },
         "waitingForLock" : <boolean>,
         "lockStats" : {
             "Global": {
                "acquireCount": {
                   "r": <NumberLong>,
                   "w": <NumberLong>,
                   "R": <NumberLong>,
                   "W": <NumberLong>
                },
                "acquireWaitCount": {
                   "r": <NumberLong>,
                   "w": <NumberLong>,
                   "R": <NumberLong>,
                   "W": <NumberLong>
                },
                "timeAcquiringMicros" : {
                   "r" : NumberLong(0),
                   "w" : NumberLong(0),
                   "R" : NumberLong(0),
                   "W" : NumberLong(0)
                },
                "deadlockCount" : {
                   "r" : NumberLong(0),
                   "w" : NumberLong(0),
                   "R" : NumberLong(0),
                   "W" : NumberLong(0)
                }
             },
             "MMAPV1Journal": {
                ...
             },
             "Database" : {
                ...
             },
             ...
         }
       },
       ...
   ],
   "fsyncLock": <boolean>,
   "info": <string>
}

Output Fields

For a complete list of db.currentOp() output fields, see currentOp.