I can't believe I have to ask this, but how do I stop a query I just ran, which is now running, and will obviously take a very long time to complete in the Mongo shell? Control+C
appears to crash the shell, and spits out a ton of errors. The silly solutions suggested in this post of course do not do anything. I understand that I could like open up another terminal tab and run db.currentOp()
, find the operation ID, and then run db.killOp()
, but I can't believe that's the only solution. I must be missing something obvious.
Edit: Use ctrl+d, which "kills the shell" according to http://www.gotothings.com/unix/bash-hotkeys.htm. If you hit this once after hitting enter in the middle of typing a command in the mongo shell, it will exit your continuation and get you back to a clean mongo prompt. Hitting it twice will exit the mongo shell.
Summary. The db. currentOp() command provides means to find all the queries that are currently running on your MongoDB server. The optional fields can be further leveraged to help filter the results to specific criteria.
Based on Alex's answer.
Query current running operations:
db.currentOp()
Kill the operation based on opid
db.killOp(30318806)
According to Mongo documentation, you should:
db.currentOp()
db.killOp()
Good example script can be found here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With