I am working on MongoDb aggregation. I am new for mongo pipelines and stuck on some point. I have documents in MongoDB collection like below. I am unable to guess how to move forward to get expected result:
{
resource: {
name: "PROJECT_01",
version: 1,
owner: ""
},
app_info: [
{
app_key: "APP_01",
size: 20,
metadata:{
deploy_on: "AWS",
status: "running",
reason:{}
}
},
{
app_key: "APP_01",
size: 20,
metadata:{
deploy_on: "azure",
status: "failed",
reason:{
message: "Connectivity Issue",
error_code: "CONNECTIVITY_ERROR"
}
}
},
{
app_key: "APP_02",
size: 20,
metadata:{
deploy_on: "AWS",
status: "running",
reason:{}
}
},
{
app_key: "APP_02",
size: 20,
metadata:{
deploy_on: "azure",
status: "failed",
reason:{
message: "Connectivity Issue",
error_code: "CONNECTIVITY_ERROR"
}
}
},
]
}
I want to combine metadata on bases of "app_key" by using aggregation and expected output should be like this:
{
resource: {
name: "PROJECT_01",
version: 1,
owner: ""
},
app_info: [
{
app_key: "APP_01",
size: 20,
metadata:[{
deploy_on: "AWS",
status: "running",
reason:{}
},
{
deploy_on: "azure",
status: "failed",
reason:{
message: "Connectivity Issue",
error_code: "CONNECTIVITY_ERROR",
}
}
]},
{
app_key: "APP_02",
size: 20,
metadata:[{
deploy_on: "AWS",
status: "running",
reason:{}
},
{
deploy_on: "azure",
status: "failed",
reason:{
message: "Connectivity Issue",
error_code: "CONNECTIVITY_ERROR"
}
}
]}
}
If someone have idea, Please share here. Thanks.