I am trying to formulate a pipeline that will do a $lookup for each item in an array of sub-documents.
so for each category.attribute i need to lookup the matching attribute document from the attributes collection.
categories collection
[
{
_id: ObjectId("123456"),
name: "Foo"
attributes: [
{
required: true,
attribute: ObjectId("098765")
},
{
required: true,
attribute: ObjectId("34509")
},
]
}
]
attributes collection
[
{
_id: ObjectId("098765"),
key: "bar"
},
{
_id: ObjectId("34509"),
key: "baz"
}
]