MQL reference navigation
$currentOp
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.
Syntax
db.adminCommand({
aggregate: 1,
pipeline: [
{
$currentOp: {
allUsers: <boolean>,
idleConnections: <boolean>,
idleCursors: <boolean>,
idleSessions: <boolean>,
localOps: <boolean>
}
}
],
cursor: {}
})Parameters
| 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. |
Examples
Example 1: List active operations
Return all currently active operations:
db.adminCommand({
aggregate: 1,
pipeline: [
{ $currentOp: { allUsers: true } }
],
cursor: {}
})Example 2: Filter active operations
Return active operations for a specific database, combined with $match:
db.adminCommand({
aggregate: 1,
pipeline: [
{ $currentOp: { allUsers: true } },
{ $match: { "ns": /^mydb\./ } }
],
cursor: {}
})