$currentOp
The $currentOp aggregation stage returns information about currently running operations in the database. This stage is useful for monitoring active queries and operations in an aggregation pipeline.
Parameters
-
allUsers(optional): When set totrue, returns operations for all users. Default isfalse. -
idleConnections(optional): When set totrue, includes idle connections. Default isfalse. -
idleCursors(optional): When set totrue, includes information about idle cursors. Default isfalse. -
idleSessions(optional): When set totrue, includes information about idle sessions. Default istrue. -
localOps(optional): When set totrue, includes local operations. Default isfalse.
Example (MongoDB Shell)
The following example demonstrates using the $currentOp aggregation stage to retrieve information about active read operations.
Query example
db.aggregate([ { $currentOp: { allUsers: true, idleConnections: false } }, { $match: { op: "query" } } ])
Output
[
{
"opid": "12345",
"active": true,
"op": "query",
"ns": "test.users",
"secs_running": 2
}
]
Code examples
To view a code example for using the $currentOp command, choose the tab for the language that you want to use: