Tutorial by Examples

retrieve all documents in a collection db.collection.find({}); retrieve documents in a collection using a condition ( similar to WHERE in MYSQL ) db.collection.find({key: value}); example db.users.find({email:"[email protected]"}); retrieve documents in a collection using Boole...
db.collection.findOne({}); the querying functionality is similar to find() but this will end execution the moment it finds one document matching its condition , if used with and empty object , it will fetch the first document and return it . findOne() mongodb api documentation
All documents from students collection. > db.students.find().pretty(); { "_id" : ObjectId("58f29a694117d1b7af126dca"), "studentNo" : 1, "firstName" : "Prosen", "lastName" : "Ghosh", "age" ...
The basic syntax of find() method with projection is as follows > db.COLLECTION_NAME.find({},{KEY:1}); If you want to show all documents without the age field then the command is as follows db.people.find({},{age : 0}); If you want to show all documents the age field then the command is a...
In MongoDB, projection means selecting only the necessary data rather than selecting whole of the data of a document. The basic syntax of find() method with projection is as follows > db.COLLECTION_NAME.find({},{KEY:1}); If you want to to show all document without the age field then the comm...
Similar to aggregation methods also by the find() method you have the possibility to limit, skip, sort and count the results. Let say we have following collection: db.test.insertMany([ {name:"Any", age:"21", status:"busy"}, {name:"Tony", age:"...

Page 1 of 1