Automattic / mongoose

MongoDB object modeling designed to work in an asynchronous environment.
https://mongoosejs.com
MIT License
26.92k stars 3.84k forks source link

Replica Set Auto Reconnect #8315

Closed edahlseng closed 4 years ago

edahlseng commented 4 years ago

Do you want to request a feature or report a bug? Ask a question

What is the current ~behavior~ question? In the documentation for the openUri function, there is an option, reconnectTries, that says (emphasis mine):

If you're connected to a single server or mongos proxy (as opposed to a replica set), the MongoDB driver will try to reconnect every reconnectInterval milliseconds for reconnectTries times, and give up afterward. When the driver gives up, the mongoose connection emits a reconnectFailed event. This option does nothing for replica set connections.

Why does reconnection not work for replica set connections? Is there another way to achieve reconnection with replica sets? (Please forgive me if this has been answered somewhere else – I checked a number of closed issues, but they all seemed to refer to bugs related to reconnect events, and I still haven't found a good answer to this question 😕.)

edahlseng commented 4 years ago

It sounds like Mongoose should automatically reconnect to replica sets regardless of the reconnect settings, and so there might be a bug here. See #8325 for more details.

vkarpov15 commented 4 years ago

When connected to a replica set, mongoose will continue to try to reconnect indefinitely. That's why the reconnectTries option does nothing for replica sets - there's no way to tell the mongodb driver to stop trying to reconnect to a replica set after a certain number of failures.