I have two collections namely; users and usersHobbies, the users collection has the following document schema
{
id: 001
name: "ABC",
age: 19,
skills: [a, b, c]
}
and userHobbies schema is as follows
{
_id: 01,
userId: 001,
favorite: 'reading',
leastFavorite: 'cooking'
totalHobbies: 6
},
//New hobby with the passage of time (new document entry)
{
_id: 02,
userId: 001,
favorite: 'coding',
pastFavorite: 'reading',
leastFavorite: 'cooking'
totalHobbies: 11
},
A user has 1-M hobbies and for each new entry, a new document is entered with the same userId (only for users who wish to update or insert new hobby), What I am now looking for is a way to merge user collection with its userHobbies collection, and bear in mind, that I want to display all users, whereas some users might not have hobbies at all. The desired find method result is as follows (the data is displayed in pseudo React DataTable)
id | * Name* | Age | Skills | Hobbies |
001 | ABC | 19 | a, b, c | coding, reading
002 | DEF | 28 | a, b, c, d |
003 | XYZ | 22 | a, b | reading
As you can see, I am retreiving all users regardless of whether or not they have 1-M hobbies merged together in Hobbies column or not
Is $lookup aggregation the right tool for this or some other aggregation query like $merge
Thanks