Created
June 6, 2014 14:12
-
-
Save nycdavid/ea8a653e054d6b696e0a to your computer and use it in GitHub Desktop.
Salud: Import script for JSON foods
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 fs = require('fs'), | |
mongoClient = require('mongodb').MongoClient, | |
foodsJson = JSON.parse(fs.readFileSync('./foods-2011-10-03.json')); | |
mongoClient.connect('mongodb://127.0.0.1:27017/salud', function(err, db) { | |
if (err) throw err; | |
var collection = db.collection('foods-orig'); | |
foodsJson.forEach(function(el, i) { | |
el.nutrients.forEach(function(el2, i) { | |
delete el2.group | |
}); | |
collection.insert({ | |
name: el.name, | |
group: el.group, | |
nutrients: el.nutrients | |
}, {}, function(err, foods) { | |
if (err) throw err; | |
console.log(foods[0].name + ': INSERTED'); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment