Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.