Created
July 1, 2013 15:15
-
-
Save bmaland/5901727 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var MongoClient = require('mongodb').MongoClient; | |
var mapFn = function() { | |
emit(1, { length: this.length }); | |
} | |
var reduceFn = function(key, values) { | |
var sum = 0; | |
values.forEach(function(doc) { | |
sum += doc.length; | |
}); | |
return { totalLength: sum }; | |
}; | |
MongoClient.connect('mongodb://10.1.4.175:27017/test', function(err, db) { | |
if(err) throw err; | |
var MR = { | |
mapreduce: "beards", | |
out: {inline: 1}, | |
map: mapFn.toString(), | |
reduce: reduceFn.toString() | |
} | |
db.executeDbCommand(MR, function(err, dbres) { | |
console.log(dbres); | |
var results = dbres.documents[0].results | |
console.log("executing map reduce, results:") | |
console.log(JSON.stringify(results)) | |
process.exit(1) | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment