У меня есть 2 коллекции adminUser и DepartmentUser , которые связаны полем adminUserId
из adminUser collection и adminUserId
из DepartmentUser collection.
Я хочу объединить эти две коллекции, которые содержат все поля обеих коллекций, независимо от того, являются ли данные общими или редкими между ними. Я попытался с помощью агрегации, но агрегация возвращает данные только с общими полями.
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" : ""
}
Вывод :
{
"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" : ""
}
}
Может кто-нибудь помочь?