12

Get all the documents out of a collection in MongoDB

 2 years ago
source link: https://dev.to/dak425/get-all-the-documents-out-of-a-collection-in-mongodb-31bp
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Small Bytes of MongoDB (4 Part Series)

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()
Enter fullscreen modeExit fullscreen mode

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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK