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 it works
Each entry shows the operator, its category and a short description, with an
example for the most common ones. The category matters because the same $ name
can behave differently depending on where it appears. A query filter, an update
document and an aggregation pipeline each use their own operator set:
// query
db.orders.find({ total: { $gt: 100 }, status: { $in: ["paid", "shipped"] } })
// update
db.orders.updateOne({ _id: id }, { $set: { status: "paid" }, $inc: { tries: 1 } })
// aggregation
db.orders.aggregate([
{ $match: { status: "paid" } },
{ $group: { _id: "$customer", spent: { $sum: "$total" } } },
{ $lookup: { from: "users", localField: "_id", foreignField: "_id", as: "user" } }
])
Tips and examples
- Put a
$matchas early as possible in a pipeline so it can use indexes and shrink the document stream before expensive later stages. - Use
$exprto compare two fields in the same document insidefind(). $elemMatchis required when you need several conditions to hold on the same array element rather than on the array as a whole.$facetlets you compute several aggregations (e.g. results plus a total count) from one input in a single round trip.