Skip to content

Instantly share code, notes, and snippets.

@mongolab-org
Created December 10, 2017 20:33
Show Gist options
  • Save mongolab-org/f7d0184f9c472b1e558281a8581d511d to your computer and use it in GitHub Desktop.
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/
// 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