Created
April 18, 2017 18:38
-
-
Save drakemccabe/4243a835ada9aa5f74ffb232dbebcbe5 to your computer and use it in GitHub Desktop.
Mongoose Aggregate within time range
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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