Created
August 12, 2014 08:50
-
-
Save elvio/a5f1cfcf9d998781a9e4 to your computer and use it in GitHub Desktop.
Map Reduce with published_at limit
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 mapFunction = function() { | |
emit(this.facebook_object_id, 1); | |
}; | |
var reduceFunction = function(key, values) { | |
return Array.sum(values); | |
}; | |
var options = { | |
query: {published_at: {$gt: new Date(2013, 1, 1)}}, | |
out: {inline: 1}, | |
}; | |
function compare(v1, v2) { | |
if (v1.value < v2.value) { | |
return -1; | |
} else if (v1.value > v2.value) { | |
return 1; | |
} else { | |
return 0; | |
} | |
} | |
var results = db.interactions.mapReduce(mapFunction, reduceFunction, options).results; | |
var sorted = results.sort(compare).reverse().splice(0, 25); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment