Question
Rebooting droplet doesn't disconnect MongoDB connection
I have two droplets running. One is running node and the other is running MongoDB. The node droplet connects to the MongoDB droplet over private networking using mongoose.
If the MongoDB droplet powers off, the mongoose connection will disconnect and when the MongoDB droplet powers on, the mongoose connection will reconnect. The problem is that when the MongoDB droplet simply reboots, the mongoose connection does not disconnect. The connection does not close but is completely unusable.
var options = {
server: {
auto_reconnect: true,
reconnectInterval: 1000,
reconnectTries: Infinity,
socketOptions: {
keepAlive: 1,
connectTimeoutMS: 1000
}
}
};
var db = mongoose.createConnection(‘snip’, options);
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×