$gt
Match values greater than 100
{ price: { $gt: 100 } } 
MongoDB operators are special keys that start with $. They tell MongoDB how to work with your data—not just which field to look at.
You use operators to query, update, aggregate, transform, compare, and manipulate documents. Without them, you could only match exact field values; with them, you can express ranges, logic, math, arrays, and pipeline stages.
Operator = instruction that starts with $
Examples:
$gt → greater than (query / expression)
$set → set a field value (update / stage)
$match → filter documents in a pipeline
$sum → total values in a $group
Browse every tutorial in the left sidebar. An operator is a named action. You place it where MongoDB expects an expression, filter, update, or stage. MongoDB reads the $name, applies the rule, and returns or modifies documents accordingly.
| Where operators appear | Typical use |
|---|---|
| Query filters | find({ age: { $gt: 18 } }) |
| Update operations | updateOne({}, { $set: { active: true } }) |
| Aggregation pipelines | aggregate([{ $match: … }, { $group: … }]) |
| Expressions | Inside $project / $addFields |
| Array / document work | $push, $pull, $filter, $map |
// Query filter
db.students.find({ score: { $gte: 80 } })
// Update
db.students.updateOne(
{ name: "Asha" },
{ $set: { grade: "A" } }
)
// Aggregation expression
db.students.aggregate([
{ $project: { total: { $add: ["$math", "$science"] } } }
]) Almost every operator uses the $operator form. The $ prefix marks a reserved name so MongoDB does not treat it as a normal field.
{ $operatorName: <argument> }
// Field-path in aggregation (different meaning of $):
"$fieldName" → value of that field on the current document $gtMatch values greater than 100
{ price: { $gt: 100 } } $setUpdate (or pipeline stage) a field
{ $set: { status: "shipped" } } $matchFilter documents in a pipeline
{ $match: { city: "Chennai" } } { total: { $sum: "$amount" } } Tip: $field as an operator means “run this action.” "$field" as a string path means “read this field.” Beginners often mix those two meanings—keep them separate.
Use this mental model before you type mongosh syntax.
goal = what you need (filter / change / transform / total)
if goal is "find matching docs":
use query operators ($gt, $in, $and, ...)
else if goal is "change stored fields":
use update operators ($set, $unset, $push, ...)
else if goal is "pipeline analytics":
use stages ($match, $group, ...)
and expression / accumulator operators inside them
for each document:
apply the operator rule
keep, change, or emit the result Major families below. The left sidebar lists individual tutorials—this section only explains when each family is useful.
| Category | Used for | Examples |
|---|---|---|
| Query & comparison | Match documents by value relationships | $eq, $gt, $in |
| Logical | Combine or negate conditions | $and, $or, $not |
| Element | Check field presence or BSON type | $exists, $type |
| Evaluation | Expressions, regex, JavaScript, schema | $expr, $regex, $jsonSchema |
| Array | Read or reshape arrays in expressions | $filter, $size, $arrayElemAt |
| Update | Change document fields in place | $set, $unset, $inc |
| Field update | Targeted field writes during updates | $set, $unset, $rename, $currentDate |
| Array update | Modify array fields during updates | $push, $pull, $addToSet, $pop |
| Aggregation | Pipeline stages and per-document expressions | $match, $add, $cond |
| Bitwise | Bit-level updates or matches on integers | $bitsAllSet, $bit |
| Geospatial | Location queries and nearness | $near, $geoWithin, $geoNear |
| Miscellaneous | Special helpers and search aids | $text, $comment, $meta |
For rollups inside $group, see the accumulators hub. For pipeline steps, see aggregation stages.
A short starter set. Open any name for a full tutorial when a page exists; use the sidebar for the complete catalog.
| Operator | Quick meaning |
|---|---|
$eq | Equal to a value |
$gt / $gte | Greater than / greater or equal |
$lt / $lte | Less than / less or equal |
$in | Value is in a list |
$and / $or | Combine conditions |
$set / $unset | Set or remove fields (update / stage) |
$push / $pull | Add to or remove from arrays |
$match / $project / $group | Core aggregation stages |
$sum | Sum values (or count with $sum: 1) |
Small students collection. We filter high scores with $gte, then average them with $group and $avg.
Three students with a numeric score.
db.students.insertMany([
{ _id: 1, name: "Asha", score: 92 },
{ _id: 2, name: "Ben", score: 74 },
{ _id: 3, name: "Chitra", score: 88 }
]); students.score.Keep scores of 80 or higher, then compute one average for that set.
db.students.aggregate([
{ $match: { score: { $gte: 80 } } },
{
$group: {
_id: null,
avgHighScore: { $avg: "$score" },
count: { $sum: 1 }
}
}
]); Match the job to the family first; then pick a specific operator.
| If you need to… | Start with |
|---|---|
| Compare values | Comparison operators ($gt, $eq, $in) |
| Combine multiple conditions | Logical operators ($and, $or) |
| Modify stored fields | Update operators ($set, $unset, $inc) |
| Transform data in a pipeline | Aggregation stages & expression operators |
| Work with arrays | Array operators / array update operators |
| Total or average many documents | Accumulators inside $group |
Common beginner traps when learning MongoDB operators.
{ score: { $gt: 80 } } works in find() / $match. Aggregation expression form is { $gt: ["$score", 80] }, often inside $expr. Same name, different shapes.
$acos belongs in expression stages, not as a plain find() filter. $set belongs in updates (or as a pipeline stage), not alone in a filter.
$$gt is an operator. "$score" is a field path. Confusing them causes syntax errors or unexpected nulls.
Missing fields often behave like null. Queries such as { field: null } can match both null and missing. Use $exists when you need to distinguish them.
Comparing against an array can match if any element satisfies the condition. Know whether your field is a scalar or an array before writing the filter.
"10" (string) is not equal to 10 (number). Store and compare consistent BSON types, or convert with operators like $toInt.
Some operators are query-only, update-only, or aggregation-only. Always check the context on the individual operator page.
| Idea | Practical tip |
|---|---|
| Operators are not “slow by default” | Cost comes from how much data you scan and how you shape the query |
| Indexes matter | Index fields you filter and sort on often ($match / find) |
| Filter early | Put $match near the start of aggregations |
| Avoid full scans | Prefer selective filters over reading every document when possible |
Use explain() when a query feels slow. Prefer correct indexes and smaller working sets over micro-optimizing a single operator choice.
$-prefixed instructions for querying, updating, and aggregating.One line: MongoDB operators are the vocabulary of filters, updates, and pipelines—pick the right family, then the right $name.
Start the operator tutorials with absolute value in aggregation expressions.
11 people found this page helpful