Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I abort a query in mongo JavaScript shell

Tags:

mongodb

Executing queries in the JavaScript shell of Mongo feels a lot like executing commands right in the bash shell. Because of this, my fingers keep trying to Ctrl+C my way out of a command that I want to "abort" and land back at the command prompt. Unfortunately, in the mongo shell at 2.0.4, when I Ctrl+C, it drops me out of the JavaScript shell, rather than just aborting the command and giving me the command prompt.

Is there a way in the JavaScript shell to abandon the current command without executing it and land back at the command prompt?

like image 511
Bob Kuhar Avatar asked Jun 08 '12 16:06

Bob Kuhar


People also ask

How do you stop a command in mongo shell?

Bottom line: Besides killOp, the only reliable way to stop an operation is to stop the cluster. Use db. currentOp() and then db. killOp() .

How do you end a query in MongoDB?

MongoDB provides two facilitates to terminate running operations: maxTimeMS() and db. killOp() . Use these operations as needed to control the behavior of operations in a MongoDB deployment.


1 Answers

What I've always naturally done is type a ( and then immediately hit enter three times. The shell will assume you are just hitting enter to break up your command, but if you hit enter 2 more times it will exit back to the shell. It's wonky, but it works.


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.

like image 170
whaley Avatar answered Oct 24 '22 23:10

whaley