Created
December 10, 2017 20:33
-
-
Save mongolab-org/f7d0184f9c472b1e558281a8581d511d to your computer and use it in GitHub Desktop.
mLab-recommended Mongoose driver options for production applications. Note: this example is for the Mongoose 4.3.x driver. For the most up-to-date information on driver settings, please visit the Node.js driver documentation: https://mongodb.github.io/node-mongodb-native/
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
// Recommended driver settings for the Mongoose 4.3.x driver. | |
var mongoose = require('mongoose'); | |
var uri = 'mongodb://<dbuser>:<dbpassword>@<host1>:<port1>,<host2>:<port2>/<dbname>?replicaSet=<replicaSetName>'; | |
var options = { | |
"server" : { | |
"socketOptions" : { | |
"keepAlive" : 300000, | |
"connectTimeoutMS" : 30000 | |
} | |
}, | |
"replset" : { | |
"socketOptions" : { | |
"keepAlive" : 300000, | |
"connectTimeoutMS" : 30000 | |
} | |
} | |
} | |
mongoose.connect(uri, options); | |
var db = mongoose.connection; | |
db.on('error', console.error.bind(console, 'connection error:')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment