Skip to content

The option ‘autoReconnect’ is incompatible with the unified topology – Mongo Error – How to fix?

Find out how to fix the MongoDB error – The option autoReconnect is incompatible with the unified topology.

This error is very similar to the other errors you might face when you send reconnect option to mongo connector.

DeprecationWarning: The option `autoReconnect` is incompatible with the unified topology, please read more by visiting http://bit.ly/2D8WfT6
...
DeprecationWarning: The option `reconnectTries` is incompatible with the unified topology, please read more by visiting http://bit.ly/2D8WfT6
...
DeprecationWarning: The option `reconnectInterval` is incompatible with the unified topology, please read more by visiting http://bit.ly/2D8WfT6

Mongodb deprecated the current server discovery and engine monitoring method, so you need to use new server and engine monitoring method. You need to pass useUnifiedTopology as true while connecting to Mongo database. But apparently this new option doesn’t support reconnectTries / autoReconnect / reconnectInterval.

mongoose.connect(url, {poolSize: 10, bufferMaxEntries: 0, reconnectTries: 5000, useNewUrlParser: true,useUnifiedTopology: true});

Please remove the option reconnectTries / autoReconnect / reconnectInterval while connecting to MongoDB either using native mongo client or via mongoose.

mongoose.connect(url, {poolSize: 10, bufferMaxEntries: 0, useNewUrlParser: true,useUnifiedTopology: true});

The latest version of MongoDB and moongoose drives automatically try to reconnect when it loses connection to MongoDB.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.