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 theadmindatabase.$currentOpoffers a better alternative to thecurrentOpcommand and thedb.currentOpmethod. The latter two commands are limited to returning all operations in a single document, which must not exceed the maximum 16MB BSON size. Since$currentOppipelines return a cursor, they are not subject to these limitations.$currentOpalso enables you to perform arbitrary transformations of the results as the documents pass through the pipeline.$currentOptakes 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
$currentOpmust be the first stage in the pipeline.- Pipelines that start with
$currentOpcan only be run on theadmindatabase. - On a standalone or replica set with authentication enabled, the
inprogprivilege is required to run$currentOpif theallUsersparameter is set to true. - On a sharded cluster, the
inprogprivilege is required to run all$currentOppipelines.
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" } }
] )