Last Updated: February 25, 2016
· jabclab

Multi-line input in Mongo shell

If you're writing complex queries in the Mongo shell you're likely to want to split it over multiple lines. The mongo shell allows you to do this as follows:

$ mongo
> EDITOR='vim'
> function myLongQuery() {}
> edit myLongQuery
# Do the editing
> myLongQuery()

Not only does this allow you multi-line queries, it also allows you to use your favourite text editor :)

Note that by default the function will only live for the duration of that mongo shell session. For more info see the MongoDB docs.

Say Thanks
Filed Under