Created
March 2, 2023 21:36
-
-
Save PonomareVlad/3f8d0c7418cb5d6261b9d83a673232a9 to your computer and use it in GitHub Desktop.
Aggregation with pipeline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.Vehicle.aggregate([ | |
{ | |
$match: {vin: "..."} | |
}, | |
{ | |
$lookup: { | |
from: 'Address', //i want all addresses | |
localField: '_vin', | |
foreignField: 'vehicle.vin', | |
as: 'addresses' | |
} | |
}, | |
{ | |
$lookup: { | |
from: 'Driver', //i wand all drivers | |
localField: '_vin', | |
foreignField: "vehicle.vin", | |
as: "drivers" | |
} | |
}, | |
{ | |
$lookup: { | |
from: "Upgrade", //i only want upgrades of type "external" (the document has a field "type":"external") | |
localField: "_vin", | |
foreignField: "vehicle.vin", | |
as: "upgrades", | |
pipeline: [ | |
{ | |
$match: { | |
type: "external" | |
} | |
} | |
] | |
} | |
} | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment