I couldn’t find an answer for this on stackoverflow although I’m sure it’s there. I need to create a chart showing summed values by the month (think summing sales totals where you have multiple orders in a given month). I need to be aware of the years too (e.g. I don’t want to sum orders/sales for december 2017 and december 2016).
I’m pulling in objects that look like the below schema:
import { Mongo } from 'meteor/mongo';
import { SimpleSchema } from 'meteor/aldeed:simple-schema';
export const Orders = new Mongo.Collection('Orders');
Orders.allow({
insert: () => false,
update: () => false,
remove: () => false,
});
Orders.deny({
insert: () => true,
update: () => true,
remove: () => true,
});
Orders.schema = new SimpleSchema({
amount: {
type: String,
optional: true
},
orderDate: {
type: Date,
optional: true
},
});
If I have two order records for december 2016, one for $1 and another for $2, I need something like this:
[
{ total: 3, month: ‘December’, year: ‘2016’ },
{ total: 1, month: ‘January’, year: ‘2017’ },
{ total: 5, month: ‘February’, year: ‘2017’ }
]