Skip to content

Instantly share code, notes, and snippets.

@pedrodelgallego
Created November 23, 2010 15:59
Show Gist options
  • Save pedrodelgallego/711987 to your computer and use it in GitHub Desktop.
Save pedrodelgallego/711987 to your computer and use it in GitHub Desktop.
A map reduce function that count the tags in a gist
use gistcube
map = function() {
if (!this.tags) {
return;
}
for (index in this.tags) {
emit(this.tags[index], 1);
}
};
reduce = function(previous, current) {
var count = 0;
for (index in current) {
count += current[index];
}
return count;
};
result = db.runCommand({
"mapreduce" : "gists",
"map" : map,
"reduce" : reduce,
"out" : "tags"});
db.tags.find()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment