Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display all results of my MongoDB query --eval in bash shell without changing in parameters?

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 ?

like image 683
user324810 Avatar asked Sep 16 '25 15:09

user324810


1 Answers

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())"
like image 200
Himanshu Sharma Avatar answered Sep 18 '25 10:09

Himanshu Sharma