Finding Documents
Query a collection using find and findOne, and control result ordering, limits, and skipping.
find and findOne
find() returns a cursor over every matching document; findOne() returns just the first match (or null), useful when you expect at most one result.
db.users.find(); // every document in the collectiondb.users.findOne({ email: "ada@example.com" }); // exactly one document, or nullFiltering with a Query Document
The first argument to find() is a query document — its fields describe conditions a matching document must satisfy.
db.users.find({ age: 28 }); // exact matchdb.users.find({ "address.city": "London" }); // matching a nested field with dot notationsort, limit, and skip
These chainable cursor methods control ordering and pagination.
db.users.find().sort({ age: -1 }); // descending by agedb.users.find().limit(10); // first 10 resultsdb.users.find().sort({ age: -1 }).skip(10).limit(10); // page 2 of 10This convention (1/-1) appears throughout MongoDB's sort syntax and elsewhere — worth committing to memory early.
Counting Documents
db.users.countDocuments({ age: { $gte: 18 } }); // count matching a filterCommon Beginner Mistakes
In application code, you typically need to convert it (e.g. .toArray() in Node.js drivers) before using array methods on the results.
skip() still scans and discards all preceding documents internally — for very large offsets, range-based pagination on an indexed field performs much better.
FAQs
Yes — an empty (or omitted) query document matches every document in the collection, just like find() with no arguments.
Yes — pass multiple keys in the sort document, e.g. { age: -1, name: 1 }, applied in the order they're listed.
Summary
find/findOne with sort/limit/skip cover the fundamentals of reading data back out of MongoDB. Next, you'll go deeper into the query operators that make filtering genuinely powerful.