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.
Here is my app.ts
:
const CONNECTION_URL = "mongodb+srv://name:<password>@cluster0.vyegx.mongodb.net/MyApp?retryWrites=true&w=majority"
mongoose.connect(CONNECTION_URL).then(_INIT_)
async function _INIT_(){
const server = app.listen(PORT, ()=>{
console.log("listening on port "+PORT+"...")
});
const io = new Server(server);
}
UPDATE It works perfectly with no errors in Heroku but when I try to run it from my computer it gives an error.