Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

No primary server available when failover happens: MongoDB, Node.js, Mongoose

Writer Olivia Zamora

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: 4.3.4 node.js version:0.10.26

4

4 Answers

I was also facing a similar problem then I just changed

mongoose.connect(db)

to

mongoose.connect(db, {useNewUrlParser: true})

and now it is working fine

I have a primary, secondary and an arbiter set up running in three different nodes. This is how I connect using mongoose and the failover works perfectly fine.

mongoose.connect('mongodb://user::27017,b.com:27017,c.com:27017/dbName');

So, everything expect mongodb:// are variables.

I had this problem but it turned out to be that I was trying to access from a non-whitelisted IP.

mongoose.connect(url, { useNewUrlParser: true, useUnifiedTopology: true }) use like this, it will work fine.

0

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy