i have two collections i want to join
houses
[
{
"name": "house1",
"events": [
{
"name": "Event1"
},
{
"name": "Event2",
"accountId": 123
}
]
}
]
accounts
[
{
"_id": 123,
"balance": 22
}
]
I want to join the 2 collections and get a result like this:
[
{
"name": "house1"
"events": [
{
"name": "Event1"
},
{
"name": "Event2",
"accountId": 123,
"account": {
"_id": 123,
"balance": 22
}
}
],
}
]
Here is my incomplete aggregate solution so far:
{
"$lookup": {
"as": "eventAccounts",
"foreignField": "_id",
"from": "accounts",
"localField": "events.accountId"
}
}
Please help