I am currently facing an issue when failover happens in mongodb replica set. The app fails to reconnect to the newly elected primary server and fails to perform all subsequent write operations.
Restarting app reconnects successfully.
The failover happens instantly and a new primary is elected. However, the app fails to connect to the new primary.
mongodb version: 3.2.6
mongoose version: 3.4.3
node.js version:0.10.26
Any help will be appreciated.
Hi,
I am currently facing an issue when failover happens in mongodb replica set. The app fails to reconnect to the newly elected primary server and fails to perform all subsequent write operations.
mongodb version: 3.2.6
mongoose version: 3.4.3
node.js version:0.10.26
You may have an outdated version of mongoose and MongoDB node.js driver. MongoDB 3.2.x is currently supported by mongoose version 4.3.0 and above, and node.js driver version 2.1.0 and above. Please see:
Also, please ensure that the connection string references a replica set (e.g: mongodb://server1:27017,server2:27017,server3:27107/dbname?replicaSet=set)
Best regards,
Kevin
Thanks Kevin,
Hi,
The mongoose version we’re using is 4.3.4 and mongodb node.js version is 2.1.2.
The connection string is properly formed.
Any other suggestions?
You may want to try setting mongoose debug flag: mongoose.set('debug', true) and see what is happening during failover.
I cannot seem to reproduce the issue you are seeing (i.e. my test application could consistently reconnect to a new Primary after a short time). It will be helpful if you can post a short, self-contained code that could consistently reproduce this problem.
Best regards,
Kevin
The issue seems to be resolved when the hostnames in replica set are repliced with corresponding host ip addresses.