MongoDB: Show Collection Data – Mongo Shell

MongoDB stores data records as documents which are gathered together in collections.

Databases in MongoDB hold one or more collections of documents.

In this short note i will show how to show collection data in MongoDB from the command-line using the mongo shell.

Show Collection Data in MongoDB

Cool Tip: To connect to a remote MongoDB server from the command-line, it needs to install MongoDB command-line client, known as mongo shell! Read More →

To show collection data in MongoDB, first of all start the mongo shell:

$ mongo

Select the database to use and list collections:

> show dbs
> use <databaseName>
> show collections

Execute one of the following commands to show collection data in MongoDB:

> db.<collectionName>.find() 

– or –

> db.<collectionName>.find().pretty() 

While showing collection data it may be useful to limit the number documents:

> db.<collectionName>.find().limit(<number>)

– or –

> db.<collectionName>.find().pretty().limit(<number>)
Was it useful? Share this post with the world!

One Reply to “MongoDB: Show Collection Data – Mongo Shell”

  1. This helped me a lot! Thanks!

Leave a Reply