100% Client-Side β’ 0 B Data Leaves Browser
database
MongoDB Query & Aggregation Pipeline Cheat Sheet
Essential MongoDB syntax reference for developers. Covers CRUD operations, query filters, projection, indexing, and aggregation pipelines.
Read & Filter Operations
Find all documents in collectiondb.collection.find()
Filter documents by exact field valuedb.collection.find({ status: "active" })
Filter with comparison operators ($gte, $lte, $ne, $in)db.collection.find({ age: { $gte: 18, $lte: 65 } })
Filter array field matching all specified elementsdb.collection.find({ tags: { $all: ["react", "node"] } })
Projection: include name and email, exclude _iddb.collection.find({}, { name: 1, email: 1, _id: 0 })
Sort descending (-1) or ascending (1) with pagination limitdb.collection.find().sort({ createdAt: -1 }).limit(10)
Create & Update Operations
Insert single JSON document into collectiondb.collection.insertOne({ ... })
Insert batch array of documentsdb.collection.insertMany([{ ... }, { ... }])
Update specific field without overwriting documentdb.collection.updateOne({ _id }, { $set: { status: "verified" } })
Atomically increment numerical field on matching recordsdb.collection.updateMany({}, { $inc: { views: 1 } })
Update document if found, or insert if does not existdb.collection.updateOne({ email }, { $set: { lastLogin: new Date() } }, { upsert: true })
Aggregation Pipeline
Filter stream documents before grouping or projection$match: { status: "paid" }
Group documents and calculate aggregate sums, averages, or counts$group: { _id: "$userId", total: { $sum: "$amount" } }
Sort grouped stream results$sort: { total: -1 }
Perform left outer join with another collection$lookup: { from: "users", localField: "userId", foreignField: "_id", as: "user" }
Deconstruct array field into separate document for each element$unwind: "$tags"
Frequently Asked Questions
β’ What is the performance difference between $set and replacing a document in MongoDB?
`$set` only modifies the specified fields in place without transferring the entire document over the network or touching unmodified fields, dramatically reducing network IO and write locks.