Is it possible to pipe results in to a pager from within a mongo shell?
The mysql cli equivalent would be:
mysql> pager less
Load JavaScript file js file from mongo shell, using the load() function. load() function allow to execute from absolute and relative paths. We can simply load a file in mongo shell with load() function. And Finally If we have lots of scripted files, We can load() inside another javaScript file.
You can execute Java Script in Mongo CLI or command prompt The print() method simply prints the data arguments that are passed into it. print("Hello From Mongo"); eg: print(data, ...); printjson(object); print(JSON.
To open up the MongoDB shell, run the mongo command from your server prompt. By default, the mongo command opens a shell connected to a locally-installed MongoDB instance running on port 27017 . Try running the mongo command with no additional parameters: mongo.
You can try to use mongo --eval option. Something like:
mongo <db> --quiet --eval '<query>' | less
Mongo shell already paginates 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 iterated up to 20 times to print up to the first 20 documents that match the query. The mongo shell will prompt Type it to iterate another 20 times.
You can set the DBQuery.shellBatchSize attribute to change the number of iteration from the default value 20.
It doesn't seem possible, but you can output to a file, and then read your file with a pager in another terminal:
$ mongo | tee file.txt
See Printing Mongo query output to a file while in the mongo shell.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With