Skip to content

Instantly share code, notes, and snippets.

@1ambda
Created January 22, 2014 12:46
Show Gist options
  • Save 1ambda/8558143 to your computer and use it in GitHub Desktop.
Save 1ambda/8558143 to your computer and use it in GitHub Desktop.
Mongoose Average Query Example
var CpuUtilization = require('./models/cpu_utilization');
CpuUtilization.aggregate({
// $match: { instance_id: { $gte: 21 }}
$match : {
instance_id : 'i-2d800b2a',
time_stamp : {
// $lt : new Date('Tue Jan 21 2014 19:31:00 GMT+0900 (대한민국 표준시)')
$lt : new Date('2014-01-21 10:31:00.000Z')
}
}
}).group({
_id : '$instance_id',
markAvg : {
$avg : '$average'
}
}).exec(function(err, res) {
if (err) {
console.log(err);
} else {
console.log(res);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment