There are many documents:
{
"_id" : ObjectId("506ddd1900a47d802702a904"),
"subid" : "s1",
"total" : "300",
"details" :[{
name:"d1", value: "100"
},
{
name:"d2", value: "200"
}]
}
{
"_id" : ObjectId("306fff1900a47d802702567"),
"subid" : "s1",
"total" : "700",
"details" : [{
name:"d1", value: "300"
},
{
name:"d8", value: "400"
}]
}
Elements in 'details' arrays may vary.
Question is: how can I get such result with aggregation framework and java?
{
"_id" : "s1",
"total" : "1000",
"details" : [{
name:"d1", value: "400"
},
{
name:"d2", value: "200"
},
{
name:"d8", value: "400"
}]
}
Or maybe I should use custom map-reduce functions here?