| title | $currentOp |
|---|---|
| description | The $currentOp stage returns information on active and queued operations for the database. |
| type | operators |
| category | aggregation |
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.
db.adminCommand({
aggregate: 1,
pipeline: [
{
$currentOp: {
allUsers: <boolean>,
idleConnections: <boolean>,
idleCursors: <boolean>,
idleSessions: <boolean>,
localOps: <boolean>
}
}
],
cursor: {}
})| Parameter | Description |
|---|---|
allUsers |
Optional. Boolean. If true, reports operations for all users. Default: false. |
idleConnections |
Optional. Boolean. If true, reports on idle connections. Default: false. |
idleCursors |
Optional. Boolean. If true, reports on idle cursors. Default: false. |
idleSessions |
Optional. Boolean. If true, reports on idle sessions. Default: false. |
localOps |
Optional. Boolean. If true, reports operations running locally on the current instance. Default: false. |
Return all currently active operations:
db.adminCommand({
aggregate: 1,
pipeline: [
{ $currentOp: { allUsers: true } }
],
cursor: {}
})Return active operations for a specific database, combined with $match:
db.adminCommand({
aggregate: 1,
pipeline: [
{ $currentOp: { allUsers: true } },
{ $match: { "ns": /^mydb\./ } }
],
cursor: {}
})- Must be first stage —
$currentOpmust be the first stage in the aggregation pipeline - Admin database only — this stage must be run against the
admindatabase usingdb.adminCommand() - Collection-agnostic — does not operate on a specific collection