I have this:
var actions = [
project: 23123,
title: 'Change of windows
energySaving: {
electricity: {
lighting: 24324,
equipment: 23423,
fans: 234234,
distribution: 234324,
chiller: 234234,
other: 234324
},
heating: {
ventilation: 234324,
shell: 23423,
tapWater: 23423
},
}
]);
This is my query to get some fields from the actions collection:
mongoose.model('Action').find({project: project._id})
.select('title description energySaving')
.exec(function(err, actions){
res.status(200).send(actions);
});
})
Instead of getting the entire "energySaving" property, I would like to replace this with a "totalEnergySaving" which is the sum of all the subobjects. Is it possible to use a aggregation to do this? If so, it's probably the $sum
feature. Not really sure how though.