I'm trying to do some aggregating with Mongo and I keep getting the error "Exception while invoking method 'pieChart' MongoError: exception $group does not support inclusion-style expressions" This is a Meteor project and I have installed the meteorhacks:aggregate package and have aggregations working in other areas of my app. This is server side code, btw. Thanks. Here is all the code:
let twentyFourHourArray = [];
let time = moment('12:00 am');
let pipeline = [
{
$match: {
$and: [
{'data.hour': time},
{'data.campaign_id': { $in: campaignIds } }
]
}
},
{$group: {
_id: time,
spend: {$sum: "$data.spend"},
clicks: {$sum: "$data.clicks"},
impressions: {$sum: "$data.impressions"},
likes: {$sum: "$data.like"}
}
}
];
for (var i = 0; i <= 24; i++) {
let result = HourlyBreakdowns.aggregate(pipeline);
result[0]['cpc'] = result[0].spend / result[0].clicks;
result[0]['cpm'] = result[0].spend / (result[0].impressions / 1000);
result[0]['cpl'] = result[0].spend / result[0].likes;
twentyFourHourArray.push(result);
time = time.add(1, 'hour');
}
Update: after some tinkering, this works. And I placed it within the for loop. Not positive, but it started working after I formatted the moment objects which turns them into strings.
var pipeline = [
{$match:
{$and: [
{'data.hour': time.format('hh:mm a')},
{'data.campaign_id': { $in: campaignIds } }
]
}
},
{$group: {
_id: time.format('hh:mm a'),
spend: {$sum: "$data.spend"},
clicks: {$sum: "$data.clicks"},
impressions: {$sum: "$data.impressions"},
likes: {$sum: "$data.like"}
}
}
];