MongoDB Operators Reference

All MongoDB query, update, aggregation and projection operators in one table.

Searchable MongoDB operator reference covering query operators, update modifiers, aggregation pipeline stages and expressions, and projection operators — including $match, $group, $lookup, $set and $expr. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

What is the difference between a query operator and an update operator?

Query operators like $gt and $in appear in the filter document and decide which documents match. Update operators like $set and $inc appear in the update document and decide how matched documents are modified.

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

OperatorCategoryWhat it does
$matchPipeline stageFilter documents, uses indexes
$groupPipeline stageGroup and accumulate
$lookupPipeline stageLeft outer join from another collection
$projectPipeline stageShape output fields
$set / $addFieldsPipeline stageAdd or overwrite fields
$unwindPipeline stageDeconstruct an array into one doc per element
$set (update)UpdateSet one or more fields to a value
$incUpdateIncrement a numeric field
$pushUpdateAppend to an array
$pullUpdateRemove matching elements from an array
$gt, $lt, $gte, $lteQueryNumeric/date range comparisons
$in, $ninQueryMatch a set of values
$existsQueryTest for field presence
$exprQueryUse aggregation expressions inside find()
$elemMatchQueryMatch a condition on a single array element

Practical tips

  • Put $match as early as possible in a pipeline so it uses indexes and shrinks the document stream before expensive later stages like $lookup or $group.
  • Use $expr to compare two fields within the same document in a find() filter — this is the only way to do per-document field comparisons outside of aggregation.
  • Use $elemMatch when you need multiple conditions on the same array element, not spread across different elements of the array.
  • $facet lets 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.
  • $min and $max appear in both update and accumulator contexts with different meanings; check the category when searching to use the right one.