Created
July 5, 2013 14:28
-
-
Save johnnyhalife/5934910 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 MongoClient = require('mongodb').MongoClient; | |
var OPTIONS = { db: { native_parser: false }, replSet: { keepAlive: 1, connectTimeoutMS: 0, socketTimeoutMS: 0 } }; | |
var current = null; | |
module.exports = function(callback) { | |
if(current && (current._state == 'connected' || current.serverConfig.isConnected())) { | |
return callback(current); | |
} | |
var url = process.env.MONGOLAB_URI + "?auto_reconnect=true&poolSize=4"; | |
MongoClient.connect(url, OPTIONS, function(err, db) { | |
if(err) throw err; | |
return callback(current = db); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment