, , , $push " ", $reduce, MongoDB 3.4, $sum :
db.collection.aggregate([
{ "$group": {
"_id": null,
"result": { "$push": "$result" }
}},
{ "$addFields": {
"result": {
"$reduce": {
"input": "$result",
"initialValue": [],
"in": {
"$map": {
"input": {
"$zip": {
"inputs": [ "$$this", "$$value" ],
"useLongestLength": true
}
},
"as": "el",
"in": { "$sum": "$$el" }
}
}
}
}
}}
])
"input" to $map $zip, "" .
, $reduce, "zipped" :
[ [0,1], [0,3], [0,5], [0,7], [0,9] ]
, useLongestLength 0 "" , .
$map, $sum, "" :
[ 1, 3, 5, 7, 9 ]
$zip "" :
[ [1,2], [3,4], [5,6], [7,8], [9,10] ]
$map , $sum, :
[ 3, 7, 11, 15, 19 ]
" " , . $reduce , .
, . , null $group "" $push .
BSON , $unwind includeArrayIndex.
, , , " " - " ", , " ". , , " " , , "" .