DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Tony Colston
Tony Colston

Posted on

slow mongo queries

You can find long running mongo queries with this

db.currentOp({"secs_running": {$gte: 20}}) 
Enter fullscreen mode Exit fullscreen mode

That will list current operations that have been running at least 20 seconds and longer.

Look at that list that returns and find opid out of each element. Also read each element some of the queries there could be system processes (or at least it looked like it for me).

Then for each opid you want to kill run this

db.killOp(<OPIDHERE>);
Enter fullscreen mode Exit fullscreen mode

The opid in my case was an int (a big one) so an example of what it looked like was this:

db.killOp(231321);
Enter fullscreen mode Exit fullscreen mode

That should save you some reboots or service restarts!

Top comments (0)

Thank you.

Β 
Thanks for visiting DEV, we’ve worked really hard to cultivate this great community and would love to have you join us. If you’d like to create an account, you can sign up here.