I have a mongo document like below;
{
"_id" : "123",
"info" : {
"batch" : "Batch1-Minor"
},
"batchElements" : {
"elements" : [
{
"_id" : "elementId1",
"type": "ABC"
},
{
"_id" : "elementId2",
"type": "ABC"
}
]
}
}
How can generate an aggregated output by changing the _id field inside elements by concatenating $info.batch and $batchElements.elements._id
Expected Output:
{
"_id" : "123",
"info" : {
"batch" : "Batch1-Minor"
},
"batchElements" : {
"elements" : [
{
"_id" : "Batch1-Minor-elementId1",
"type": "ABC"
},
{
"_id" : "Batch1-Minor-elementId2",
"type": "ABC"
}
]
}
}
$out-- will overwrite the collection if existing or create a new &$merge- will write to new collection or create new (These two are not what we're looking at), So it has to be a normal update process, What is mongoDB version ?