Created
August 21, 2017 20:26
-
-
Save Debdut/6c87dbfc806a67c064b36baa069e18ac to your computer and use it in GitHub Desktop.
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 http = require('http'); | |
var MongoClient = require('mongodb').MongoClient; | |
var url = "mongodb://localhost:27017/testdb"; | |
var companies = [{'name' : 'Sun Pharma', 'medicine' : [1, 2]}, | |
{'name' : 'Hello Pharma', 'medicine' : [3, 4]}, | |
{'name' : 'Sayan Pharma Ltd.', 'medicine' : [5]}]; | |
MongoClient.connect(url, (err, db) => { | |
if (err) { | |
console.log (err); | |
} else { | |
db.createCollection ('company', (err, collection) => { | |
var index = 0; | |
companies.forEach ((company) => { | |
collection.insert (company, () => { | |
if (index++ === companies.length-1) | |
{ | |
collection.find ().toArray ((err, result) => { | |
db.close (() => { | |
console.log (result); | |
}); | |
}); | |
}; | |
}); | |
}); | |
}); | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment