简体   繁体   中英

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 database and mongoose for its driver. I am using 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 its not working.

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

need to set useUnifiedTopology: false

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM