Get all the documents out of a collection in MongoDB

For a full overview of MongoDB and all my posts on it, check out my overview.

The most simple way to read all the documents out of a collection in MongoDB is to use the find method on a collection.

Let's say you have a collection in your database called users. If you wanted to read all the documents out of it, you can do this:

db.users.find()

This will return a cursor that you can iterate over to get each document from the collection. Keep in mind, most tooling you can use to interact with your data will automatically do some iteration for you.


Did you find this information useful? If so, consider heading over to my donation page and drop me some support.

Want to ask a question or just chat? Contact me here