Skip to content

Instantly share code, notes, and snippets.

@heukirne
Created November 7, 2013 11:48
Show Gist options
  • Save heukirne/7353359 to your computer and use it in GitHub Desktop.
Save heukirne/7353359 to your computer and use it in GitHub Desktop.
Map/Reduce no Mongo para coleção de Posts
map = function() {
this.textContent.split(' ').forEach(
function(word){ emit(word,1); }
);
};
reduce = function(key, values) {
var count = 0;
values.forEach(
function(value) { count += value; }
);
return count;
};
db.posts.mapReduce(map, reduce, {out : {replace:"results"}});
db.result.find().limit(10).sort({value:-1})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment