Created
January 22, 2014 12:03
-
-
Save 1ambda/8557586 to your computer and use it in GitHub Desktop.
mongoDB get Average
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
db.networkouts.group( | |
{ cond: {"instance_id": 'i-6da51c6a'} | |
, initial: {count: 0, total:0} | |
, reduce: function(doc, out){ out.count++; out.total += doc.average } | |
, finalize: function(out){ out.avg = out.total / out.count } | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
db.networkouts.group(
{ cond: {"instance_id": 'i-6da51c6a', time_stamp: {$lte: new Date('Tue Jan 21 2014 19:31:00 GMT+0900 (대한민국 표준시)')}}
, initial: {count: 0, total:0}
, reduce: function(doc, out){ out.count++; out.total += doc.average }
, finalize: function(out){ out.avg = out.total / out.count }
} );