Skip to content

Instantly share code, notes, and snippets.

@drakemccabe
Created April 18, 2017 18:38
Show Gist options
  • Save drakemccabe/4243a835ada9aa5f74ffb232dbebcbe5 to your computer and use it in GitHub Desktop.
Save drakemccabe/4243a835ada9aa5f74ffb232dbebcbe5 to your computer and use it in GitHub Desktop.
Mongoose Aggregate within time range
wrapper.aggregate = function(startDate, endDate) {
var model = mongoose.model('Action');
model.aggregate([
{'$match': { cd: { '$gt': startDate, '$lt': endDate }, actionType: 'Click' }},
{'$group': { _id: '$ad', clk: { '$sum': '$value' }}}
]).exec(function(err, results) {
console.log(results);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment