Created
August 25, 2014 14:04
-
-
Save xentatt/f561522146b7aab48826 to your computer and use it in GitHub Desktop.
NodeJS + MongoDB
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
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