MongoDB Aggregation: Combine two arrays MongoDB Aggregation: Combine two arrays mongodb mongodb

MongoDB Aggregation: Combine two arrays


An alternative solution with neither aggregation framework nor map/reduce:

db.sens.find().forEach(function (doc) {   doc.data.forEach(function(dataElement) {      var sumArray = [];      for (var j = 0; j < dataElement.flow.length; j++) {         sumArray[j] = dataElement.flow[j] + dataElement.occupancy[j];      }      dataElement.sum = sumArray;      collection.save(doc);   });});