MQL reference navigation

$currentOp

The $currentOp stage returns a stream of documents containing information on active and queued operations for the database instance. This stage must be the first stage in the pipeline and is run on the admin database.

Syntax

db.adminCommand({
  aggregate: 1,
  pipeline: [
    {
      $currentOp: {
        allUsers: <boolean>,
        idleConnections: <boolean>,
        idleCursors: <boolean>,
        idleSessions: <boolean>,
        localOps: <boolean>
      }
    }
  ],
  cursor: {}
})

Parameters

ParameterDescription
allUsersOptional. Boolean. If true, reports operations for all users. Default: false.
idleConnectionsOptional. Boolean. If true, reports on idle connections. Default: false.
idleCursorsOptional. Boolean. If true, reports on idle cursors. Default: false.
idleSessionsOptional. Boolean. If true, reports on idle sessions. Default: false.
localOpsOptional. Boolean. If true, reports operations running locally on the current instance. Default: false.

Examples

Example 1: List active operations

Return all currently active operations:

db.adminCommand({
  aggregate: 1,
  pipeline: [
    { $currentOp: { allUsers: true } }
  ],
  cursor: {}
})

Example 2: Filter active operations

Return active operations for a specific database, combined with $match:

db.adminCommand({
  aggregate: 1,
  pipeline: [
    { $currentOp: { allUsers: true } },
    { $match: { "ns": /^mydb\./ } }
  ],
  cursor: {}
})

Key Takeaways

  • Must be first stage$currentOp must be the first stage in the aggregation pipeline
  • Admin database only — this stage must be run against the admin database using db.adminCommand()
  • Collection-agnostic — does not operate on a specific collection