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.

CategoryMonitoring & Diagnostics
MongoDB Version1.0+
Example Languagemongosh (Shell)

📝 Syntax

db.currentOp()
db.currentOp({ active: true, secs_running: { $gt: 5 } })
db.killOp(<opid>)

⚙️ Parameters

activeReturn only operations where active is true
secs_runningFilter 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

📚 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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏