Skip to content

Instantly share code, notes, and snippets.

@elvio
Created August 12, 2014 08:50
Show Gist options
  • Save elvio/a5f1cfcf9d998781a9e4 to your computer and use it in GitHub Desktop.
Save elvio/a5f1cfcf9d998781a9e4 to your computer and use it in GitHub Desktop.
Map Reduce with published_at limit
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