currentOp (Active Operations)
Last updated: 2026-10-09
currentOp (Active Operations)
currentOp lists operations currently executing, for diagnosing slow queries and long-running work (blocked writes, open transactions). Each entry exposes opid, client, ns, secs_running, and command; pair it with db.killOp(opid) to terminate. Call db.currentOp({ active: true }) directly in mongosh.
| Category | Monitoring & Diagnostics |
|---|---|
| MongoDB Version | 1.0+ |
| Example Language | mongosh (Shell) |
📝 Syntax
db.currentOp()
db.currentOp({ active: true, secs_running: { $gt: 5 } })
db.killOp(<opid>)
⚙️ Parameters
| active | Return only operations where active is true |
|---|---|
| secs_running | Filter by seconds running (e.g. $gt: 5) |
Returns:Returns an inprog array with one detail document per operation
▶ Example
Run the commands below in your local mongosh (requires a running mongod):
// currentOp: find operations running over 5 seconds
db.currentOp({ active: true, secs_running: { $gt: 5 } })
// kill it with the opid
// db.killOp(12345)
Output:
{ inprog: [ { opid: 12345, secs_running: 12, ns: 'shop.orders' } ], ok: 1 }
📌 Notes
- The $currentOp aggregation pipeline filters precisely (namespace, command, etc.)
- killOp aborts the op, but transaction rollback can still take time
- Requires inprog privileges such as clusterMonitor
🏷️ Related Tags
💡 Related Cases
📚 Related Tutorials
❓ FAQ
QHow do I find slow queries?
ARun db.currentOp({ active: true, secs_running: { $gt: 5 } }) and sort by secs_running.
QHow do I kill a stuck operation?
ATake the opid from currentOp and run db.killOp(opid).
QDoes currentOp require privileges?
AYes — inprog/killop privileges; regular users only see their own operations.