Rebooting droplet doesn't disconnect MongoDB connection

March 12, 2016 377 views
MongoDB DigitalOcean Node.js Ubuntu

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);

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.

Have another answer? Share your knowledge.