Hi,
How to perform a lookup from an array of objects in a foreign collection?
Example:
user collection:
{
"uId": "user1"
}
Match Details Collection:
{
"matchId": 123,
"users": [
{
"uId": "user1",
"session": "active",
},
{
"uId": "user2",
"session": "active",
},
],
}
How do I perform a lookup on Match Details Collection where the users.uId is the link between these two collections without the use of the $unwind stage inside the pipeline parameter of the $lookup stage.
I tried using the $eq operator, but it didn’t work.
{
"$lookup": {
"from": "matchDetails",
"let": {"userId": "$uId"},
pipeline: [
{
"$match": {
"$expr": {
"$eq": ["$users.uId", "$$userId"], // <-- This doesn't work. Dont want to use `$unwind` before `$match` stage
},
},
},
],
}
}