0 votes
in MongoDB by

How to print out more than 20 items (documents) in MongoDB’s shell in MongoDB?

1 Answer

0 votes
by
db.foo.find().limit(300)

won’t do it… it still prints out 20

db.foo.find().toArray()

db.foo.find().forEach(printjson)

will both print out very expanded view of each document instead of the 1-line version for find():

DBQuery.shellBatchSize = 300

will do.

MongoDB Docs – Getting Started with the mongo Shell – Executing Queries

You can use it inside of the shell to iterate over the next 20 results. Just type it if you see “has more” and you will see the next 20 items.

from the shell if you want to show all results you could do db.collection.find().toArray() to get all results without it

Could always do:

db.foo.find().forEach(function(f){print(tojson(f, ”, true));});

To get that compact view.

Also, I find it very useful to limit the fields returned by the find so:

db.foo.find({},{name:1}).forEach(function(f){print(tojson(f, ”, true));});

which would return only the _id and name field from foo.

Related questions

0 votes
asked Dec 5, 2020 in Agile by SakshiSharma
+1 vote
asked Jan 16, 2020 in NoSQL by sharadyadav1986
...