Last active
August 29, 2015 14:05
-
-
Save jobsamuel/2df70c806a61ad28242e to your computer and use it in GitHub Desktop.
MongoDB connection close error
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/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