1

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);
}
I have tried to whitelist my ip, but it's not working.

UPDATE It works perfectly with no errors in Heroku but when I try to run it from my computer it gives an error.

PeskyGnat
  • 2,454
  • 19
  • 22
Billjesh Baidya
  • 189
  • 1
  • 12

1 Answers1

0

need to set useUnifiedTopology: false

Mohammad Ali Rony
  • 4,695
  • 3
  • 19
  • 33