How to split output inside mango shell

Is it possible to output results to a pager from the mongo shell?

mysql cli equivalent:

mysql> pager less

+6
source share
3 answers

The Mongo shell already parses the results if the returned cursor is not assigned to a variable. From the documentation:

... in the mongo shell, if the returned cursor is not assigned to a variable using the var keyword, then the cursor is automatically repeated up to 20 times to print up to the first 20 documents that match the query. The mongo shell will offer to enter it into iteration 20 more times.

You can set the DBQuery.shellBatchSize attribute to change the iteration number from the default value of 20.

+2
source

You can try using the mongo --eval option. Sort of:

mngo <db> --quiet --eval '<query>' | less 
+2
source

This is not possible, but you can output it to a file and then read the file with the pager in another terminal:

 $ mongo | tee file.txt 

See Printing Mongo query output to a file in the mongo shell .

+1
source

All Articles