rmbswq
Last Updated: February 25, 2016
·
4.426K
· jabclab
4f4bf0fbd4cc6de6159d78f9f9fb3aa6

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
Respond
Filed Under