currentOp

Definition

currentOp

Returns a document that contains information on in-progress operations for the mongod instance.

currentOp has the following form:

{ currentOp: 1 }

The mongo shell provides the db.currentOp() wrapper for the currentOp command.

Behavior

currentOp must run against the admin database, and it can accept several optional fields.

Field Description
"$ownOps"

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

On mongod instances, users are always authorized to run currentOp with "$ownOps": true to view their own operations. See access control.

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.

"$all": true overrides any output field filters.

<filter> Specify filter conditions on the Output Fields. See Examples.

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.

Starting in 3.2.9, users can use $ownOps on mongod instances to view their own operations without the inprog privilege action.

db.adminCommand( { currentOp: 1, "$ownOps": 1 } )

Examples

The following examples use the currentOp command with various query documents to filter the output.

Display All Current Operations

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

Write Operations Waiting for a Lock

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

Changed in version 3.6.

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

Active Operations with no Yields

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

db.adminCommand(
   {
     currentOp: true,
     "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.adminCommand(
   {
     currentOp: true,
     "active" : true,
     "secs_running" : { "$gt" : 3 },
     "ns" : /^db1\./
   }
)

Active Indexing Operations

Changed in version 3.6.

The following example returns information on index creation operations:

db.adminCommand(
    {
      currentOp: true,
      $or: [
        { op: "command", "command.createIndexes": { $exists: true }  },
        { op: "none", "msg" : /^Index Build/ }
      ]
    }
)

Output Example

The following is a prototype of the currentOp output when run on a standalone:

{
  "inprog": [
       {
         "host" : <string>,
         "desc" : <string>,
         "connectionId" : <number>,
         "client" : <string>,
         "appName" : <string>,
         "clientMetadata" : <document>,
         "active" : <boolean>,
         "currentOpTime" : <string>,
         "opid" : <number>,
         "secs_running" : <NumberLong()>,
         "microsecs_running" : <number>,
         "op" : <string>,
         "ns" : <string>,
         "command" : <document>,
         "originatingCommand" : <document>,
         "planSummary": <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>,
   "ok": 1
}

The following is a prototype of the currentOp output when run on a primary of a replica set: