On this page
$currentOp (aggregation)
On this page
Definition
New in version 3.6.
$currentOp
-
Returns a stream of documents containing information on active and/or dormant operations for the MongoDB deployment. To run
$currentOp
, use thedb.aggregate()
helper on theadmin
database.$currentOp
offers a better alternative to thecurrentOp
command and thedb.currentOp
method. The latter two commands are limited to returning all operations in a single document, which must not exceed the maximum 16MB BSON size. Since$currentOp
pipelines return a cursor, they are not subject to these limitations.$currentOp
also enables you to perform arbitrary transformations of the results as the documents pass through the pipeline.$currentOp
takes an options document as its operand.{ $currentOp: { allUsers: <boolean>, idleConnections: <boolean> } }
Specify an empty document to use the default values.
Behavior
Option | Description |
---|---|
allUsers |
Boolean. If set to Note The Defaults to |
idleConnections |
Boolean. If set to Defaults to |
Constraints
$currentOp
must be the first stage in the pipeline.- Pipelines that start with
$currentOp
can only be run on theadmin
database. - On a standalone or replica set with authentication enabled, the
inprog
privilege is required to run$currentOp
if theallUsers
parameter is set to true. - On a sharded cluster, the
inprog
privilege is required to run all$currentOp
pipelines.
Example
The following example runs the $currentOp
operation in the first stage and filters the results of that operation in the second stage.
use admin
db.aggregate( [
{ $currentOp : { allUsers: true, idleConnections: true } },
{ $match : { shard: "shard01" } }
] )