In this case, aggregation is much simpler and much more efficient than mapReduce:
db.collection.aggregate({
$group: {
_id: '',
subida: { $sum: '$subida' }
}
}, {
$project: {
_id: 0,
subida: '$subida'
}
})
- use $group with $sum to calculate sum
- use projection’s $project operator to remove id key required by $group operator