Aggregation structure is not only an aggregation conveyor.
Of course, you can also use map reduction with really simple functions:
var map_function = function(){ for(var i=0;i<this.vals.length;i++){ emit(i,this.vals[i]); } } var reduce_function = function(key, values){ return Array.sum(values) }
The output is a list of documents, where _id is the index and value is the sum. Like this:
[{u'_id': 0.0, u'value': 3.0}, {u'_id': 1.0, u'value': 5.0}, {u'_id': 2.0, u'value': 7.0}, {u'_id': 3.0, u'value': 9.0}]
David mabodo
source share