Skip to content

Instantly share code, notes, and snippets.

@IrakliJani
Created January 2, 2013 18:44
Show Gist options
  • Save IrakliJani/4436789 to your computer and use it in GitHub Desktop.
Save IrakliJani/4436789 to your computer and use it in GitHub Desktop.
MongoDB simple mapReduce (counts chars in a wordlist)
map = function(){
word = this.word.split("");
chars = {};
for(var i in word)
if(! chars[word[i]])
chars[word[i]] = 1;
else
chars[word[i]]++;
for(var c in chars)
emit(c, chars[c]);
}
reduce = function(key, values){
sum = 0
for(var i in values)
sum += values[i]
return sum;
}
finalize = function(key, value){
return value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment