Last active
October 17, 2017 14:20
-
-
Save ConnectedReasoning/5b2f0c5c7d430c94ef602c91dd79397a to your computer and use it in GitHub Desktop.
Insert array into a Mongo collection
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; | |
var url = "mongodb://localhost:27017/yourMongoDB"; | |
var data = require("./dataFile.json"); | |
MongoClient.connect(url, function(err, db){ | |
if(err){ | |
console.log(err); | |
} else { | |
db.collection('yourCollection').insertMany(data).then(() => { | |
console.log("inserted!"); | |
db.close(); | |
}).catch(error => { | |
console.log("this error occured: ", error); | |
}); | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment