Skip to content

Instantly share code, notes, and snippets.

@fsschmitt
Created August 5, 2016 08:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fsschmitt/ca5f8c520767dc65142be24791a5c750 to your computer and use it in GitHub Desktop.
Save fsschmitt/ca5f8c520767dc65142be24791a5c750 to your computer and use it in GitHub Desktop.
Map/Reduce Documents inserted per minute
map = function() {
var datetime = this._id.getTimestamp();
var created_at_minute = new Date(datetime.getFullYear(),
datetime.getMonth(),
datetime.getDate(),
datetime.getHours(),
datetime.getMinutes());
emit(created_at_minute, {count: 1});
}
reduce = function(key, values) {
var total = 0;
for(var i = 0; i < values.length; i++) { total += values[i].count; }
return {count: total};
}
db.so.mapReduce( map, reduce, { out: 'inline' } );
db.inline.find();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment