Docs Home → Develop Applications → MongoDB Manual
db.currentOp()![](/docs/v5.3/assets/link.svg)
Definition![](/docs/v5.3/assets/link.svg)
db.currentOp()
Returns a document that contains information on in-progress operations for the database instance. The
db.currentOp()
method wraps the database commandcurrentOp
.Note
Starting in MongoDB 5.0, the
$currentOp
aggregation stage is used when running the helper methoddb.currentOp()
withmongosh
.Given this, in the 5.0 version of the shell and with mongosh,
db.currentOp()
result sets are not subject to the 16MB BSON document return size document return size limit for documents of the previous legacymongo
versions.
Syntax![](/docs/v5.3/assets/link.svg)
db.currentOp()
has the following form:
db.currentOp(<operations>)
db.currentOp()
can take the following optional
argument:
Parameter | Type | Description |
---|---|---|
boolean or document | Optional. Specifies the operations to report on. Can pass either a boolean or a document:
|
Behavior![](/docs/v5.3/assets/link.svg)
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 On |
"$all" | Boolean. If set to If the document includes |
<filter> | Specify filter conditions on the Output Fields. See Examples. If the document includes |
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:
getMore
(OP_GET_MORE andcommand
)
These operations are also included in the logging of
slow queries (see slowOpThresholdMs
for
more information about slow query logging).
Access Control![](/docs/v5.3/assets/link.svg)
On systems running with authorization
, the user
must have access that includes the inprog
privilege
action.
Starting in 3.2.9, users can run db.currentOp( { "$ownOps": true }
)
on mongod
instances to view their own operations
even without the inprog
privilege action.
Tip
Examples![](/docs/v5.3/assets/link.svg)
The following examples use the db.currentOp()
method with
various query documents to filter the output.
Write Operations Waiting for a Lock![](/docs/v5.3/assets/link.svg)
Changed in version 3.6.
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" ] } }, { "command.findandmodify": { $exists: true } } ] } )
Active Operations with no Yields![](/docs/v5.3/assets/link.svg)
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![](/docs/v5.3/assets/link.svg)
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![](/docs/v5.3/assets/link.svg)
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![](/docs/v5.3/assets/link.svg)
The following is a prototype of db.currentOp()
output.
Output Fields![](/docs/v5.3/assets/link.svg)
For a complete list of db.currentOp()
output fields, see
currentOp.