We can fetch documents by using the find method as follows:
- Selecting all documents in a collection: We can fetch all the documents from a collection like this:
> db.<collection>.find()
This operation is the same as the following SQL statement:
SELECT FROM <table>
Let's fetch all the documents from the user collection as follows:
> db.user.find()
You should get a similar result to this:
{ "_id" : ObjectId("5ca..."), "name" : "Alexandre", "slug" :
"alexandre", ... }
{ "_id" : ObjectId("5ca..."), "name" : "Pooya", "slug" : "pooya", ... }
{ "_id" : ObjectId("5ca..."), "name" : "Sébastien", "slug" :
"sebastien", ... }
- Specifying equality condition: We can fetch specific documents from a collection like this:
> db.<collection>.find(<query>...