Hello @venkata_sreekanth_bhagavatula, Welcome to the MongoDB community Forum
There are a few fixes needed in your query,
-
$match
stage in$lookup
, you need to use$expr
operator to match internal properties and$in
operator for an array of ids,
{
"$match": {
"$expr": {
"$in": ["$vid", "$$backbone_vid"]
}
}
}
- You need to use
$$ROOT
to access current document with$push
operator in$group
stage
"$push": "$$ROOT"
- Change to name as property in name in
$lookup
from"as": "feature.vid"
to"as": "features.vid"
Final Query
db.backbone.aggregate([
{
"$match": {
"structureGroupIdentifier": "164"
}
},
{
"$unwind": {
"path": "$features",
"preserveNullAndEmptyArrays": true
}
},
{
"$lookup": {
"from": "values_master_collection",
"let": {
"backbone_vid": "$features.vid"
},
"pipeline": [
{
"$match": {
"$expr": {
"$in": [
"$vid",
"$$backbone_vid"
]
}
}
},
{
"$group": {
"_id": "$vid",
"vidLanguages": {
"$push": "$$ROOT"
}
}
}
],
"as": "features.vid"
}
}
])