Using multiple lines to enter aggregation statements

Here is a dumb question, I enter a pipeline variable statement in the mongo shell, say:

> var pipeline = [ {
... $match: {
..... 'genres': { '$all': [ 'Western', 'Drama' ] },
..... 'year': { '$gt': 1940 }
..... }
... } ]

If I then up-arrow to edit the statement; it doesn’t retain the multiple lines, it is coalesces into one line:

> var pipeline = [{ $match: { 'genres': { '$all': ['Western', 'Drama'] }, 'year': { '$gt': 1940 } } }]

Is it possible to retain the multiline format? I tried writing it in another editor and pasting into the shell but that produces an error.

thanks.

You can set up an external editor for use in mongosh. This seems to keep the vertical whitespace.

Once you have the editor set up, you just type edit inside mongosh to start the external editor. Write your command there and then exit the editor which should paste the command into the shell (it will be written on a single line here). If you want to edit the command, just type edit once more and it should open up formatted like you had originally written it.

2 Likes

brilliant, thanks for the tip

2 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.