4

When I execute my --eval MongoDB query in bash shell, it returns the 20 first results and then says Type "it" for more. However, I would like to display all of the results.

This question here explains how to query through bash terminal. In the comment section of the accepted answer, someone asks how to display more of the results. Another question asks how to print out more than 20 documents but this changes the default options of MongoDB, something I don't wish to do.

This is the following shell command:

mongo --quiet myDB --eval "printjson(db.PatientsObservedMutations_hg38.find({Sample: 'test-exome-1_hg38'}).pretty().shellPrint())"

In short, is there a way to display all the results using the --eval in my bash shell after querying with mongoDB ?

user324810
  • 597
  • 8
  • 20

1 Answers1

7

To print all the records, we can use toArray() method. It converts the iterator(returned by find() method) to an array.

The following query can get us the expected output:

mongo --quiet myDB --eval "printjson(db.PatientsObservedMutations_hg38.find({Sample: 'test-exome-1_hg38'}).toArray())"
Himanshu Sharma
  • 2,940
  • 1
  • 7
  • 18