MongooseServerSelectionError: connect ETIMEDOUT

I recently ran into this problem. When I try to run my Node.js app, I get this error MongooseServerSelectionError: connect ETIMEDOUT . It also said type: 'ReplicaSetNoPrimary' . For the past few months it was working perfectly and I had never got this error. I am using MongoDB Atlas for the database and Mongoose for its driver. I am using the latest version of Mongoose and mongodb.

I tried to host the app on heroku and it works perfectly with no errors, but when I try to run it from my PC it gives that error. I tried to whitelist ip address it didn’t help. I also tried to allow the port in firewall. I disabled the firewall still not working. I dont know what is going wrong. I ran into this problem yesterday.