find(filter, projection) is the workhorse of MongoDB. The filter selects documents, the projection selects fields.
mongosh
db.products.find({ category: "electronics" })
// only name and price, hide _id
db.products.find(
{ category: "electronics" },
{ name: 1, price: 1, _id: 0 }
)Cursor methods
find() returns a cursor you can chain: .sort(), .limit(), .skip(), .count(). Sort takes 1 for ascending and -1 for descending.
mongosh
db.products.find()
.sort({ price: -1 }) // most expensive first
.skip(5)
.limit(5) // page 2 of 5-per-pagefindOne and dot notation
findOne() returns a single document (or null). Query nested fields with dot notation — always quote the path:
mongosh
db.users.findOne({ "address.city": "Mumbai" })