Let's say I have two fields member and userData in the same collection like below.
{
member: [
{ _id: ObjectId("60ff03a462256b70fdb979dc"), role: "admin" },
{ _id: ObjectId("60ff03a462256b70fdb97932"), role: "member" },
{ _id: ObjectId("60ff03a462256b70fdb97995"), role: "member" },
],
userData: [
{
_id: ObjectId("60ff03a462256b70fdb979dc"),
name: "Kevin",
email: "[email protected]",
...
},
{
_id: ObjectId("60ff03a462256b70fdb97932"),
name: "Andrew"
email: "[email protected]",
...
},
{
_id: ObjectId("60ff03a462256b70fdb97995"),
name: "Jessica",
email: "[email protected]",
...
},
....
]
}
How can I merge the two fields(essentially inserting member into userData) by their _id to populate this result?
userWithRole: [
{
_id: ObjectId("60ff03a462256b70fdb979dc"),
name: "Kevin",
email: "[email protected]",
role: "admin"
... // all other user data
}