I have documents in mongo collection like this:
{
resource: {
name: "PROJ01",
version: 1,
owner: ""
},
appInfos: [
{
app_key: "APP01",
size: 20mb,
metadata:{
deployOn: "aws",
status: "running",
reason:{}
}
},
{
app_key: "APP01",
size: 20mb,
metadata:{
deployOn: "azure",
status: "failed",
reason:{
message: "Connectivity Issue",
errorCode: "CONNECTIVITY_ERROR"
}
}
},
{
app_key: "APP02",
size: 20mb,
metadata:{
deployOn: "aws",
status: "running",
reason:{}
}
},
{
app_key: "APP02",
size: 20mb,
metadata:{
deployOn: "azure",
status: "failed",
reason:{
message: "Connectivity Issue",
errorCode: "CONNECTIVITY_ERROR"
}
}
},
]
}
I want to combine metadata on bases of “app_key” by using aggregation and expected output should be like this:
{
resource: {
name: "PROJ01",
version: 1,
owner: ""
},
appInfos: [
{
app_key: "APP01",
size: 20mb,
metadata:[{
deployOn: "aws",
status: "running",
reason:{}
},
{
deployOn: "azure",
status: "failed",
reason:{
message: "Connectivity Issue",
errorCode: "CONNECTIVITY_ERROR"
}
}
]},
{
app_key: "APP02",
size: 20mb,
metadata:[{
deployOn: "aws",
status: "running",
reason:{}
},
{
deployOn: "azure",
status: "failed",
reason:{
message: "Connectivity Issue",
errorCode: "CONNECTIVITY_ERROR"
}
}
]}
}