简体   繁体   English

MongooseServerSelectionError:连接 ETIMEDOUT

[英]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 .当我尝试运行我的节点 js 应用程序时,我收到此错误MongooseServerSelectionError: connect ETIMEDOUT It also said type: 'ReplicaSetNoPrimary' .它还说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.我使用 MongoDB 地图集作为数据库,使用 mongoose 作为其驱动程序。 I am using latest version of mongoose.我正在使用最新版本的 mongoose。

Here is my app.ts :这是我的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. 我试图将我的 ip 列入白名单,但它不起作用。

UPDATE It works perfectly with no errors in heroku but when I try to run it from my computer it gives error更新它在 heroku 中完美运行,没有错误,但是当我尝试从我的计算机运行它时,它给出了错误

need to set useUnifiedTopology: false需要设置useUnifiedTopology: false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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