Hanysamir - Mongodb Cheat Sheet Issr Master
Hanysamir - Mongodb Cheat Sheet Issr Master
syntax Description Example $lookup Performs a left outer join to a collection in db.ord‐
sort({field_‐ find first matching document db.sales.find().so‐ the same database to filter in documents ers.aggre‐
name:1 or -1}) rt({"price": 1}) from the "joined" collection for processing. gate( [ {
The $lookup stage adds a new array field $lookup: {
limit(n) Limits the number of db.sales.find().li‐
to each input document. The new array from: "inv‐
documents mit(3)
field contains the matching documents entory",
skip(n) Skips over the specified db.sales.find().sk‐
from the "joined" collection. The $lookup localField: "‐
number of documents ip(3)
stage passes these reshaped documents item", foreig‐
1 = ascending order to the next stage. nField: "‐
-1 = descending order sku", as: "‐
inventory‐
Aggregation Pipeline _docs" } } ] )
syntax Description Example The $lookup takes a document with these fields:
Logical operators
Comparison operators
syntax Description
$eq Matches values that are equal to a specified value.
$ne Matches all values that are not equal to a specified value.
$gt Matches values that are greater than a specified value.
$gte Matches values that are greater than or equal to a specified
value.
$lt Matches values that are less than a specified value.
$lte Matches values that are less than or equal to a specified
value.
$in Matches any of the values specified in an array
$nin Matches none of the values specified in an array.