I have 2 collections adminUser and departmentUser which are linked by field adminUserId from adminUser collection and adminUserId from departmentUser collection.
I want to merge these two collections which contain all fields of both collections whether data is common or uncommon between them. I tried by using aggregation but aggregation returns data with common fields only.
adminUser:
{
"adminUserId" : "1"
"userName" : "Smith",
"position" : "Head"
},
{
"adminUserId" : "2"
"userName" : "Joe",
"position" : "Lead"
},
{
"adminUserId" : "3"
"userName" : "Mark",
"position" : "Lead"
}
departmentUser:
{
"userId" : "1"
"userName" : "Leslie",
"position" : "Head",
"adminUserId" : ""
},
{
"userId" : "2"
"userName" : "Joe",
"position" : "Lead",
"adminUserId" : "2"
},
{
"userId" : "3"
"userName" : "Mark",
"position" : "Lead",
"adminUserId" : "3"
},
{
"userId" : "4"
"userName" : "Allen",
"position" : "Lead",
"adminUserId" : ""
}
Output:
{
"adminUserId" : "1"
"userName" : "Smith",
"position" : "Head"
},
{
"adminUserId" : "2"
"userName" : "Joe",
"position" : "Lead",
"departmentUserinfo":{
"userId" : "2"
"userName" : "Joe",
"position" : "Lead",
"adminUserId" : "2"
}
},
{
"adminUserId" : "3"
"userName" : "Mark",
"position" : "Lead",
"departmentUserinfo":{
"userId" : "2"
"userName" : "Mark",
"position" : "Lead",
"adminUserId" : "3"
}
},
{
"adminUserId" : ""
"userName" : "",
"position" : "",
"departmentUserinfo":{
"userId" : "1"
"userName" : "Leslie",
"position" : "Head",
"adminUserId" : ""
}
},
{
"adminUserId" : ""
"userName" : "",
"position" : "",
"departmentUserinfo":{
"userId" : "4"
"userName" : "Allen",
"position" : "Lead",
"adminUserId" : ""
}
}
Can anyone help?