Skip to content

Instantly share code, notes, and snippets.

@1ambda
Created January 22, 2014 12:03
Show Gist options
  • Save 1ambda/8557586 to your computer and use it in GitHub Desktop.
Save 1ambda/8557586 to your computer and use it in GitHub Desktop.
mongoDB get Average
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 }
} );
@1ambda
Copy link
Author

1ambda commented Jan 22, 2014

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 }
} );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment