I'm facing a roadblock in my mongodb aggregation process. Within the mongodb document, there is an array called details.
{
user: "userName1",
details: [{
adminId: "admin123",
id: "1",
name: "name1",
available: true,
address: "address1"
}, {
adminId: "admin123",
id: "2",
name: "name2",
available: false,
address: "address2"
}]
}
The task at hand is to compare the following data with the details in the document and add those entries that are not present in the details using aggregation:
// comparing data
data = [{
adminId: "admin123",
id: "1",
name: "name1",
address: "address1"
},{
adminId: "admin123",
id: "2",
name: "name2",
address: "address2"
},{
adminId: "admin123",
id: "3",
name: "name3",
address: "address3"
},{
adminId: "admin123",
id: "4",
name: "name4",
address: "address4"
}]
This is the desired output after performing the aggregation:
// expected response from database after aggregation
{
user: "userName1",
details: [{
adminId: "admin123",
id: "1",
name: "name1",
available: true,
address: "address1"
},{
adminId: "admin123",
id: "2",
name: "name2",
available: false,
address: "address2"
},{
adminId: "admin123",
id: "3",
name: "name3",
address: "address3"
},{
adminId: "admin123",
id: "4",
name: "name4",
address: "address4"
}]
}