After setting useUnifiedTopology=true
, the Auto Reconnect stopped working and generates the following ERRORS:
DeprecationWarning: The option `reconnectInterval` is incompatible with the unified topology
DeprecationWarning: The option `reconnectTries` is incompatible with the unified topology
DeprecationWarning: The option `autoReconnect` is incompatible with the unified topology
How can i get the server to auto-reconnect with that new flag?
I'm using mongoose.createConnection
to connect with the following options:
{
autoReconnect: true,
keepAliveInitialDelay: 300000,
connectTimeoutMS: 300000,
reconnectTries: Number.MAX_VALUE,
reconnectInterval: 1000,
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
poolSize: 10,
auth: {
authSource: "admin"
},
user: process.env.MONGO_USER,
pass: process.env.MONGO_PASS
}
How to use it. The unified topology is available now behind the useUnifiedTopology feature flag. You can opt in to using it by passing the option to your MongoClient constructor: const client = MongoClient('mongodb://localhost:27017', { useUnifiedTopology: true });
useUnifiedTopology: False by default. Set to true to opt in to using the MongoDB driver's new connection management engine. You should set this option to true , except for the unlikely case that it prevents you from maintaining a stable connection.
The unified topology is the first step in a paradigm shift away from a concept of “connecting” to a MongoDB deployment using a connect method.
According to the docs you shouldn't usually set autoReconnect
in combination with useUnifiedTopology
Source: https://mongoosejs.com/docs/connections.html#options
autoReconnect - The underlying MongoDB driver will automatically try to reconnect when it loses connection to MongoDB. Unless you are an extremely advanced user that wants to manage their own connection pool, do not set this option to false.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With