Skip to content

Instantly share code, notes, and snippets.

@jobsamuel
Last active August 29, 2015 14:05
Show Gist options
  • Save jobsamuel/2df70c806a61ad28242e to your computer and use it in GitHub Desktop.
Save jobsamuel/2df70c806a61ad28242e to your computer and use it in GitHub Desktop.
MongoDB connection close error
var MongoClient = require('mongodb').MongoClient;
MongoClient.connect('mongodb://localhost:27017/course', function(err, db) {
if(err) throw err;
for (var i = 0; i<10; i++) {
var fields = ["Engineering", "Medicine", "Marketing"];
var langs = ["EN", "POR", "ES"];
var doc = {user: i, field: fields[Math.round(Math.random()*2)], language: langs[Math.round(Math.random()*2)] }
db.collection('students').insert(doc, function(err, inserted) {
if(err) {
console.log(err.message);
}
return db.close(); // Everything is being inserted OK but I still receiving a "Connection Close by Application" error. WHY?
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment