Skip to content

Instantly share code, notes, and snippets.

@xentatt
Created August 25, 2014 14:04
Show Gist options
  • Save xentatt/f561522146b7aab48826 to your computer and use it in GitHub Desktop.
Save xentatt/f561522146b7aab48826 to your computer and use it in GitHub Desktop.
NodeJS + MongoDB
var MongoClient = require('mongodb').MongoClient;
MongoClient.connect('mongodb://localhost:27017/weather', function(err, db) {
if(err) throw err;
var map = function() {
emit(this["State"], 1);
}
var reduce = function(key, values) {
return Array.sum(values);
}
db.collection('data').mapReduce(map, reduce, {out: {inline: false}}, function(err, collection){
if(err) throw err;
console.dir(collection);
db.close();
});
console.dir("Calling, be patient please...");
});
results:
'Calling, be patient please...'
[ { _id: 'California', value: 744 },
{ _id: 'Florida', value: 733 },
{ _id: 'New Mexico', value: 742 },
{ _id: 'Vermont', value: 744 } ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment