Created
June 4, 2010 12:48
-
-
Save kurokikaze/425369 to your computer and use it in GitHub Desktop.
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
db.open(function(err, db) { | |
db.collection('rounds', function(err, collection) { | |
var name_letter = 'v'; | |
var map = function() { | |
if (this.score1 > this.score2) { | |
emit(this.player1, this.score1); | |
} else { | |
if (this.score2 > this.score1) emit(this.player2, this.score2) | |
} | |
}; | |
var reduce = function (k, vals) {var sum = 0;for(var i in vals) sum += vals[i];return (sum / vals.length); }; | |
collection.mapReduce(map, reduce, function(err, result) { | |
if (err) { | |
sys.puts('Err: ' + JSON.stringify(err)); | |
} else { | |
result.findOne({'_id':'kze'}, function(err, scores) { | |
if (err) { | |
sys.puts('Err in results'); | |
} | |
sys.puts('Kaze scores: ' + JSON.stringify(scores)); | |
}); | |
sys.puts('Mapreduce done'); | |
} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment