I have a mongoose collection that looks like this
[{
_type:'video',
_id:'video1',
status:'active'
},
{
_type:'video',
_id:'video2',
status:'active'
}]
And another collection like this
[{
_type:'product',
_id:'product1',
items:['video1']
}]
How can i use mongoose aggregate to find all documents with a _type of 'video' that are referenced in the field 'items' of any document with a _type of 'product'
What i want as a result
[{
_type:'video',
_id:'video1',
status:'active'
}]
this is what i have so far, but 'connectedVideos' is always an empty array
[{
"$match":{
"_type":"product"
}
},
{
"$project": {
"items":true,
"_id":true,
"title":true
}
},
{
"$unwind":"$items"
},
{
"$lookup": {
"from": "videos",
"localField": "items",
"foreignField": "_id",
"as": "connectedVideos"
}
}
]