Created
November 7, 2013 11:48
-
-
Save heukirne/7353359 to your computer and use it in GitHub Desktop.
Map/Reduce no Mongo para coleção de Posts
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() { | |
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