Rebooting droplet doesn't disconnect MongoDB connection

Posted March 12, 2016 2.4k views

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.

Submit an Answer
1 answer


This looks good, what errors are you getting when trying to connect after a reboot or pull information? Have you tried increasing or decreasing the connectTimeoutMS or reconnectInterval? It’s important to understand when asking for assistance or advice to provide as much information as you can.

Currently I’m not sure how to replicate the problem you are having, so we need a bit more information. Have you tried connecting outside the node application? Perhaps it’s at the application level?

Are the reboots planned and initiated by you, unplanned, both?

If you can provide more information, a better solution may be available, but it’s a bit difficult with the limited information.