Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

mongodb

People also ask

How many documents can a MongoDB collection hold?

If you specify a maximum number of documents for a capped collection using the max parameter to create, the limit must be less than 2^32 documents. If you do not specify a maximum number of documents when creating a capped collection, there is no limit on the number of documents.

How do I copy an entire collection in MongoDB?

Right-click on collection1 collection in DB Explorer and select Duplicate 'collection1' Collection... item in the popup menu. Specify destination collection name, duplication parameters and click Duplicate.

How do I print a MongoDB database?

In mongo shell: db. collection. findOne() prints the returned document in a well formatted JSON. To print the result (one or more documents) of find() in a formatted way, use db.


DBQuery.shellBatchSize = 300

MongoDB Docs - Configure the mongo Shell - Change the mongo Shell Batch Size


From the shell you can use:

db.collection.find().toArray()

to display all documents without having to use it.


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.


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.