I read this article on connection pooling with mongodb/nodejs. There he opens the connection once, and leaves it at that.
This is how I set up the database connection in my app.js
file:
mongodb.MongoClient.connect(MONGODB_URI, function (error, database) {
if (error) throw error;
db = database; // db is defined outside this callback
coll = db.collection('testData'); // coll is defined outside this callback
});
This is going to leave the db connection open as long as the server is running. Shouldn't you close the connection at some point? Or is it of no consequence to leave it open?