I have two collections, products and properties.
I'm doing a lookup such as:
[{
$match: {
category_id: mongoose.Types.ObjectId(category_id)
}
},
{
$lookup: {
from: "properties",
localField: "category_id",
foreignField: "category_id",
as: "properties"
}
}
]
This is basically getting me all of the products that match the category_id and including the properties that match the same category_id.
I need to add an additional check, for some_id on the properties result. In otherwords, the properties should be grouped by the some_id that is returned from the products collection and matches the same key in properties. Does that make sense? Basically having the ability to have multiple local/foreign field definitions.
any idea how I could this?
$filter? Something like{ $addFields: { properties: { $filter: { input: "$properties", as: "result", cond: { $eq: ["$$result.some_id ", "$some_id"] } } } } }