Created
August 5, 2016 08:45
-
-
Save fsschmitt/ca5f8c520767dc65142be24791a5c750 to your computer and use it in GitHub Desktop.
Map/Reduce Documents inserted per minute
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
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