0

I'm connecting to the mongo with reconnect options on the startup and using created db over the whole app.

var options = {
    "server": {
      "auto_reconnect": true,
      "poolSize": 10,
      "socketOptions": {
        "keepAlive": 1
       }
    },
    "db": {
      "numberOfRetries": 60,
      "retryMiliSeconds": 5000
    }
  };

MongoClient.connect(dbName, options).then(useDb).catch(errorHandler)

When I restart mongo server, driver reconnect successful. If I stop server and start it after a 30 second I get MongoError "topology was destroyed" on every operation. This 30 second seems to me is a default value for numberOfRetries = 5 and my given option doesn't have effect. Am I doing something wrong? How can I manage reconnection for a long time?

smirnov
  • 413
  • 3
  • 9

1 Answers1

0

According to this answer, in order to fix this error, you should increase connection timeout in the options:

var options = {
  "server": {
    "auto_reconnect": true,
    "poolSize": 10,
    "socketOptions": {
      "keepAlive": 1,
      "connectTimeoutMS": 30000 // increased connection timeout
     }
  },
  "db": {
    "numberOfRetries": 60,
    "retryMiliSeconds": 5000
  }
};
Community
  • 1
  • 1
Dmytro Shevchenko
  • 33,431
  • 6
  • 51
  • 67