In a hosted MEAN stack application, the following happened with the MongoDB replica set, which is reported by the technical support of the hosting company:
There was a three-minute window in which the first primary was elected in the first place. It seems that some network problems caused the primary to lose contact with the secondary. The window was only 3 minutes, and the primary was then re-elected as usual.
As soon as everything returned to normal, my Node.js application, which uses the Mongoose structure, did not restore its connection to the primary one, as a result of which the error “Unable to write to secondary” was registered.
Question: What settings when using Mongoose and / or the MongoDB driver that it uses can prevent automatic reconnection after the initial switch? (i.e. how can I prevent this from happening again?)
Using Mongoose v3.8.26
source
share