Created
June 8, 2015 13:33
-
-
Save fiveisprime/311cbbdd690aabbd9685 to your computer and use it in GitHub Desktop.
Reconnect on error with mongoose.
This file contains hidden or 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
db.on('error', function(error) { | |
console.error('Error in MongoDb connection: %j', error); | |
mongoose.disconnect(); | |
}); | |
db.on('disconnected', function() { | |
console.log('MongoDB disconnected!'); | |
mongoose.connect(config.mongo.uri, config.mongo.options); | |
}); | |
// | |
// Ensure that `options` has `server: { auto_reconnect: true }` | |
// | |
mongoose.connect(config.mongo.uri, config.mongo.options); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment