I'm trying to use mapreduce to calculate monthly sales and graph with chart.js later.
Suppose I have a JSON response with fields, amount and date.
For my map function, I took out the month:
month = _.map([items[i].transactionDate], function(date) {
return {
lables: items[i].transactionDate.slice(5,7)
};
});
and for my reduce function ... well I didn't know what to do here.
sum = _.reduce([items[i].amt], function(memo, num) {
return memo + items[i].amt
});
I realized that this will eventually calculate total sum not per month. Problem is that I don't know how to relate the two functions properly.
Edit: Per request, my JSON :
"items": [
{
"_id": "56d1cf3704aee3c68d89cc09",
"amt": 5,
"transactionDate": "2016-02-27T16:30:47.561Z",
}
]
and what I'm trying to get out of this is sales per month on a graph. so far I've been able to project months and total sale but not sales per a specific month.
transactionDatebut in json there is nothing like that..