> For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt

<!--
Tab options on this page. Append to the .md URL to filter:
  ?tabs=<id,...>   select specific tabs (e.g. ?tabs=nodejs,shell)
  ?allTabs=true    include every tab
  (no param)       default: one tab per tabset

Available tabs:
  other tabs: standalone, repl, shardedcluster
-->

# db.currentOp() (mongosh method)

## Definition

**Important:**

We recommend using the [`$currentOp`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp.md#mongodb-pipeline-pipe.-currentOp) aggregation stage instead of the [`currentOp`](https://www.mongodb.com/docs/manual/reference/command/currentOp.md#mongodb-dbcommand-dbcmd.currentOp) command (deprecated with version 6.2) and the [`db.currentOp()`](https://www.mongodb.com/docs/manual/reference/method/db.currentOp.md#mongodb-method-db.currentOp) method.

Returns a [document](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-document) that contains information on in-progress operations for the database instance. The [`db.currentOp()`](https://www.mongodb.com/docs/manual/reference/method/db.currentOp.md#mongodb-method-db.currentOp) method wraps the database command [`currentOp`.](https://www.mongodb.com/docs/manual/reference/command/currentOp.md#mongodb-dbcommand-dbcmd.currentOp)

**Note:**

Starting in MongoDB 5.0, the [`$currentOp`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp.md#mongodb-pipeline-pipe.-currentOp) aggregation stage is used when running the helper method [`db.currentOp()`](https://www.mongodb.com/docs/manual/reference/method/db.currentOp.md#mongodb-method-db.currentOp) with [`mongosh`.](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh)

Given this, in the 5.0 version of the shell and with mongosh, [`db.currentOp()`](https://www.mongodb.com/docs/manual/reference/method/db.currentOp.md#mongodb-method-db.currentOp) result sets are not subject to the [16MB BSON document return size](https://www.mongodb.com/docs/manual/reference/limits.md#std-label-limit-bson-document-size) document return size limit for documents of the previous legacy `mongo` versions.

## Compatibility

This method is available in deployments hosted in the following environments:

- [MongoDB Atlas](https://www.mongodb.com/docs/atlas): The fully managed service for MongoDB deployments in the cloud

**Important:**

This command is not supported in M0 and Flex clusters. For more information, see [Unsupported Commands.](https://www.mongodb.com/docs/atlas/unsupported-commands/)

- [MongoDB Enterprise](https://www.mongodb.com/docs/manual/administration/install-enterprise.md#std-label-install-mdb-enterprise): The subscription-based, self-managed version of MongoDB

- [MongoDB Community](https://www.mongodb.com/docs/manual/administration/install-community.md#std-label-install-mdb-community-edition): The source-available, free-to-use, and self-managed version of MongoDB

### Syntax

[`db.currentOp()`](https://www.mongodb.com/docs/manual/reference/method/db.currentOp.md#mongodb-method-db.currentOp) has the following form:

```javascript
db.currentOp(<operations>)
```

[`db.currentOp()`](https://www.mongodb.com/docs/manual/reference/method/db.currentOp.md#mongodb-method-db.currentOp) can take the following *optional* argument:

| Parameter | Type | Description |
| --- | --- | --- |
| [operations](https://www.mongodb.com/docs/manual/reference/method/db.currentOp.md#std-label-method-currentop-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 those operations that match the conditions. See [Behavior](https://www.mongodb.com/docs/manual/reference/method/db.currentOp.md#std-label-currentOp-behavior) for details. |

## Behavior

[`db.currentOp()`](https://www.mongodb.com/docs/manual/reference/method/db.currentOp.md#mongodb-method-db.currentOp) can accept a filter document or a boolean parameter.

If you pass a filter document to [`db.currentOp()`](https://www.mongodb.com/docs/manual/reference/method/db.currentOp.md#mongodb-method-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`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) instances, users can always run `db.currentOp( { "$ownOps": true } )` to view their own operations. |
| `"$all"` | Boolean. If set to `true`, returns information on all operations, including operations on idle connections and system operations. For more information, see [$currentOp (Aggregation Stage).](https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp.md#std-label-current-op-agg) If the document includes `"$all": true` along with [Output Fields](https://www.mongodb.com/docs/manual/reference/method/db.currentOp.md#std-label-db.currentOp-output-fields) conditions, only the `"$all":true` applies. |
| <filter> | Specify filter conditions on the [Output Fields](https://www.mongodb.com/docs/manual/reference/method/db.currentOp.md#std-label-db.currentOp-output-fields). See [Examples.](https://www.mongodb.com/docs/manual/reference/method/db.currentOp.md#std-label-currentOp-method-examples) If the document includes `"$all": true` along with [Output Fields](https://www.mongodb.com/docs/manual/reference/method/db.currentOp.md#std-label-db.currentOp-output-fields) conditions, only the `"$all":
                true` applies. |

Passing in `true` to [`db.currentOp()`](https://www.mongodb.com/docs/manual/reference/method/db.currentOp.md#mongodb-method-db.currentOp) is equivalent to passing in a document of `{ "$all": true }`. The following operations are equivalent:

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

[`db.currentOp()`](https://www.mongodb.com/docs/manual/reference/method/db.currentOp.md#mongodb-method-db.currentOp) and the [database profiler](https://www.mongodb.com/docs/manual/tutorial/manage-the-database-profiler.md#std-label-database-profiler) report the same basic diagnostic information for all CRUD operations, including the following:

- [`aggregate`](https://www.mongodb.com/docs/manual/reference/command/aggregate.md#mongodb-dbcommand-dbcmd.aggregate)

- [`count`](https://www.mongodb.com/docs/manual/reference/command/count.md#mongodb-dbcommand-dbcmd.count)

- [`delete`](https://www.mongodb.com/docs/manual/reference/command/delete.md#mongodb-dbcommand-dbcmd.delete)

- [`distinct`](https://www.mongodb.com/docs/manual/reference/command/distinct.md#mongodb-dbcommand-dbcmd.distinct)

- `find` ([OP\_QUERY](https://www.mongodb.com/docs/manual/legacy-opcodes.md#std-label-wire-op-query) and [`command`)](https://www.mongodb.com/docs/manual/reference/command/find.md#mongodb-dbcommand-dbcmd.find)

- [`findAndModify`](https://www.mongodb.com/docs/manual/reference/command/findAndModify.md#mongodb-dbcommand-dbcmd.findAndModify)

- `getMore` ([OP\_GET\_MORE](https://www.mongodb.com/docs/manual/legacy-opcodes.md#std-label-wire-op-query) and [`command`)](https://www.mongodb.com/docs/manual/reference/command/getMore.md#mongodb-dbcommand-dbcmd.getMore)

- [`insert`](https://www.mongodb.com/docs/manual/reference/command/insert.md#mongodb-dbcommand-dbcmd.insert)

- [`mapReduce`](https://www.mongodb.com/docs/manual/reference/command/mapReduce.md#mongodb-dbcommand-dbcmd.mapReduce)

- [`update`](https://www.mongodb.com/docs/manual/reference/command/update.md#mongodb-dbcommand-dbcmd.update)

These operations are also included in the logging of slow queries. See [`slowOpThresholdMs`](https://www.mongodb.com/docs/manual/reference/configuration-options.md#mongodb-setting-operationProfiling.slowOpThresholdMs) for more information about slow query logging.

## Access Control

On systems running with [`authorization`](https://www.mongodb.com/docs/manual/reference/configuration-options.md#mongodb-setting-security.authorization), the user must have access that includes the [`inprog`](https://www.mongodb.com/docs/manual/reference/privilege-actions.md#mongodb-authaction-inprog) privilege action.

Users can run `db.currentOp( { "$ownOps": true }
)` on [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) instances to view their own operations even without the [`inprog`](https://www.mongodb.com/docs/manual/reference/privilege-actions.md#mongodb-authaction-inprog) privilege action.

**See also:**

[Create a Role to Manage Current Operations](https://www.mongodb.com/docs/manual/tutorial/manage-users-and-roles.md#std-label-create-role-to-manage-ops)

## Examples

The following examples use the [`db.currentOp()`](https://www.mongodb.com/docs/manual/reference/method/db.currentOp.md#mongodb-method-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:

```javascript
db.currentOp(
   {
     "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:

```javascript
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:

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

### Active Indexing Operations

The following example returns information on index creation operations on any number of fields:

```javascript
db.getSiblingDB("admin").aggregate( [
   { $currentOp : { idleConnections: true } },
   { $match: {
         $or: [
            { "op": "command", "command.createIndexes": { $exists: true } },
            { "op": "none", "msg": /^Index Build/ }
         ]
      }
   }
] )
```

**Note:**

Active Indexing Operations do not apply to [rolling index builds.](https://www.mongodb.com/docs/manual/core/rolling-index-builds.md#std-label-rolling-index-build)

## Output Example

The following is a prototype of [`db.currentOp()`](https://www.mongodb.com/docs/manual/reference/method/db.currentOp.md#mongodb-method-db.currentOp) output.

### Standalone

The following is a prototype of the [`currentOp`](https://www.mongodb.com/docs/manual/reference/command/currentOp.md#mongodb-dbcommand-dbcmd.currentOp) output when run on a standalone:

```javascript
{
  "inprog": [
       {
         "type" : <string>,
         "host" : <string>,
         "desc" : <string>,
         "connectionId" : <number>,
         "client" : <string>,
         "appName" : <string>,
         "clientMetadata" : <document>,
         "active" : <boolean>,
         "currentOpTime" : <string>,
         "effectiveUsers" : [
            {
               "user" : <string>,
               "db" : <string>
            }
         ],
         "opid" : <number>,
         "lsid" : {
            "id" : <UUID>,
            "uid" : <BinData>
         },
         "secs_running" : <Long()>,
         "microsecs_running" : <number>,
         "op" : <string>,
         "ns" : <string>,
         "command" : <document>,
         "queryFramework" : <string>,
         "planSummary": <string>,
         "inUseTrackedMemBytes": <Long()>,  // Starting in 8.3
         "peakTrackedMemBytes": <Long()>,   // Starting in 8.3
         "cursor" : {                              // only for getMore operations
            "cursorId" : <Long()>,
            "createdDate" : <ISODate()>,
            "lastAccessDate" : <ISODate()>,
            "nDocsReturned" : <Long()>,
            "nBatchesReturned" : <Long()>,
            "noCursorTimeout" : <boolean>,
            "tailable" : <boolean>,
            "awaitData" : <boolean>,
            "originatingCommand" : <document>,
            "planSummary" : <string>,
            "operationUsingCursorId" : <Long()>
         },
         "msg": <string>,
         "progress" : {
             "done" : <number>,
             "total" : <number>
         },
         "killPending" : <boolean>,
         "numYields" : <number>,
         "dataThroughputLastSecond" : <number>,
         "dataThroughputAverage" : <number>,
         "locks" : {
             "ParallelBatchWriterMode" : <string>,
             "ReplicationStateTransition" : <string>,
             "Global" : <string>,
             "Database" : <string>,
             "Collection" : <string>,
             "Metadata" : <string>,
             "oplog" : <string>
         },
         "waitingForLock" : <boolean>,
         "lockStats" : {
             "ParallelBatchWriterMode" : {
                "acquireCount": {
                   "r": <NumberLong>,
                   "w": <NumberLong>,
                   "R": <NumberLong>,
                   "W": <NumberLong>
                },
                "acquireWaitCount": {
                   "r": <NumberLong>,
                   "w": <NumberLong>,
                   "R": <NumberLong>,
                   "W": <NumberLong>
                },
                "timeAcquiringMicros" : {
                   "r" : Long(0),
                   "w" : Long(0),
                   "R" : Long(0),
                   "W" : Long(0)
                },
                "deadlockCount" : {
                   "r" : Long(0),
                   "w" : Long(0),
                   "R" : Long(0),
                   "W" : Long(0)
                }
             },
             "ReplicationStateTransition" : {
                ...
             },
             "Global": {
                ...
             },
             "Database" : {
                ...
             },
             ...
         }
       },
       ...
   ],
   "fsyncLock": <boolean>,
   "info": <string>,
    "ok": <num>
}
```

## Specific Output Examples

These output samples illustrate `currentOp` output for particular operations. The fields that make up the actual output vary depending on the server's role.

### Resharding Output Example

```javascript
{
    shard: '<string>',
    totalCopyTimeElapsedSecs: Long('<count>'),
    totalApplyTimeElapsedSecs: Long('<count>'),
    totalCriticalSectionTimeElapsedSecs: Long('<count>'),
    totalIndexBuildTimeElapsedSecs: Long('<count>'),
    indexesToBuild: Long('<count>'),
    indexesBuilt: Long('<count>'),
    oplogEntriesFetched: Long('<count>'),
    oplogEntriesApplied: Long('<count>'),
    insertsApplied: Long('<count>'),
    updatesApplied: Long('<count>'),
    deletesApplied: Long('<count>'),
    type: 'op',
    desc: 'ReshardingMetrics{Donor|Recipient|Coordinator}Service <reshardingUUID>',
    op: 'command',
    ns: '<database>.<collection>',
    originatingCommand: {
       reshardCollection: '<database>.<collection>',
       key: '<shardkey>',
       unique:'<boolean>',
       collation: { locale: 'simple' }
    },
    totalOperationTimeElapsedSecs: Long('<count>'),
    recipientState: '<service state>',
    remainingOperationTimeEstimatedSecs: Long('<count>'),
    approxDocumentsToCopy: Long('<count>'),
    approxBytesToCopy: Long('<count>'),
    bytesCopied: Long('<count>'),
    countWritesToStashCollections: Long('<count>'),
    documentsCopied: Long('<count>'),
    provenance: 'reshardCollection'
}
```

## Output Fields

For a complete list of [`db.currentOp()`](https://www.mongodb.com/docs/manual/reference/method/db.currentOp.md#mongodb-method-db.currentOp) output fields, see [currentOp.](https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp.md#std-label-currentOp-stage-output-fields)
