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)