/    /  MongoDB – Select Document

MongoDB – Select Document:

In MongoDB, we can retrieve all documents in a collection by using the below command. This will retrieve all the documents with in the collection.

Syntax:

db.collection_name.find()
db.collection_name.find({})

Both of the above queries will work in same way. Also, you can use several other methods and conditions while retrieving the documents in a collection as per the requirement.

Example:

testset:PRIMARY>db.students.find()
{ "_id" : ObjectId("59245acd5273c93ad95b109b"),	"firstname" : "Maria",	"city" : "Banglore" }
{ "_id" : ObjectId("59246d4b5273c93ad95b109c"), "firstname" : "sneha",	"city" : "Delhi" }
{ "_id" : ObjectId("59246d7b5273c93ad95b109d"), "firstname" : "jay",	"city" : "toronto" }