Find the right MongoDB operator fast
MongoDB operators span several worlds: query operators that filter documents, update modifiers that change them, aggregation pipeline stages that transform a stream of documents, aggregation expressions that compute values, and projection operators that shape the output. This reference lets you search all of them by name or description and filter by category. It runs entirely in your browser.
How the operator categories work
The category is not cosmetic — MongoDB uses the same $ prefix for operators
across all contexts, but an operator’s meaning depends entirely on where it appears.
Putting a query operator in an update document (or vice versa) produces an error or
silently does nothing.
Query operators — used inside the filter argument of find, findOne,
updateMany, and deleteMany:
db.products.find({ price: { $gt: 10, $lt: 50 }, tags: { $in: ["sale", "new"] } })
Update operators — used inside the update argument of updateOne, updateMany,
findOneAndUpdate:
db.products.updateOne({ _id: id }, {
$set: { status: "active" },
$inc: { views: 1 },
$push: { tags: "featured" }
})
Aggregation pipeline stages — elements of the array passed to .aggregate().
Each stage transforms the stream of documents:
db.orders.aggregate([
{ $match: { status: "paid" } },
{ $group: { _id: "$customer", total: { $sum: "$amount" } } },
{ $sort: { total: -1 } },
{ $limit: 10 },
{ $lookup: { from: "users", localField: "_id", foreignField: "_id", as: "user" } }
])
Aggregation expressions — used inside pipeline stages to compute values.
$sum, $avg, $concat, $dateToString, and so on are expressions, not stages.
The most commonly reached-for operators
| Operator | Category | What it does |
|---|---|---|
$match | Pipeline stage | Filter documents, uses indexes |
$group | Pipeline stage | Group and accumulate |
$lookup | Pipeline stage | Left outer join from another collection |
$project | Pipeline stage | Shape output fields |
$set / $addFields | Pipeline stage | Add or overwrite fields |
$unwind | Pipeline stage | Deconstruct an array into one doc per element |
$set (update) | Update | Set one or more fields to a value |
$inc | Update | Increment a numeric field |
$push | Update | Append to an array |
$pull | Update | Remove matching elements from an array |
$gt, $lt, $gte, $lte | Query | Numeric/date range comparisons |
$in, $nin | Query | Match a set of values |
$exists | Query | Test for field presence |
$expr | Query | Use aggregation expressions inside find() |
$elemMatch | Query | Match a condition on a single array element |
Practical tips
- Put
$matchas early as possible in a pipeline so it uses indexes and shrinks the document stream before expensive later stages like$lookupor$group. - Use
$exprto compare two fields within the same document in afind()filter — this is the only way to do per-document field comparisons outside of aggregation. - Use
$elemMatchwhen you need multiple conditions on the same array element, not spread across different elements of the array. $facetlets you run multiple aggregation sub-pipelines on the same input in a single round trip — useful for getting paginated results plus a total count at once.$minand$maxappear in both update and accumulator contexts with different meanings; check the category when searching to use the right one.