I have two collections. USERS
{
"_id" : "myid",
"createdAt" : ISODate("2020-12-26T14:00:11.624Z"),
"email" : "[email protected]"
}
GROUPS
{
"_id" : "myidgroup",
"createdAt" : ISODate("2020-12-26T14:00:11.624Z"),
"name" : "student"
"userIds": ["myUserId1", "myUserId2"]
}
I want to do a $lookup to the groups collection to get all users with groups
| email | groups. |
|---------------------|------------------|
| [email protected] | student |
I expected output like this:
[
{
_id: "myUserId"
email: "[email protected]",
groups: [
{
"_id": "myGroupId",
"name": "student"
}
]
}
]
I know we can do it with new $lookup in mongodb 3.6 and above but I am using mongodb 3.4.
Any help is greatly appreciated.
$matchto get users, but I have no idea when I$lookupto the groups of users because in the groups userIds is an array