Created
September 5, 2012 11:32
-
-
Save rhyskeepence/3635341 to your computer and use it in GitHub Desktop.
group by day via map reduce
This file contains hidden or 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
var m = function() { | |
emit(this._id - (this._id % 86400000), { aggregate:0, count:1, sum: this['threadCount'] } ); | |
}; | |
var r = function (name, values) { | |
var result = { aggregate:0, count:0, sum:0 }; | |
values.forEach(function(f) { | |
result.sum += f.sum; | |
result.count += f.count; | |
}); | |
return result; | |
}; | |
var f = function (who, res) { | |
if (res.count > 0) res.aggregate = res.sum / res.count; | |
return res; | |
}; | |
db.prod.mapReduce(m, r, {finalize: f, query: { "_id": { $gte: someTimestamp }}, out: { inline : 1 }}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment