本文介绍了连接到 MongoDb Atlas 服务器时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我目前正在编写一个 Web 应用程序,我需要数据库,所以我决定使用 mongodb 和 mongoose.到目前为止,我在 localhost 上测试了所有内容并且它工作正常,但我想将数据移动到服务器.我听说过 Atlas 并注册了自己并上传"了数据.

So I'm currently wirting a web application and I need database so I decided to go with mongodb and mongoose. Until now I tested everything on localhost and it worked but I wanted to move the data to a server. I had heard of Atlas and registered myself and "uploaded" the data.

现在我想通过 node.js 应用程序连接到集群.

Now I want to connect to the cluster via a node.js app.

mongoose.connect('mongodb+srv://engllucas:p%[email protected]/test');

我在连接你的应用程序

然后我交换了密码.

mongoose.connect('mongodb://engllucas:p%[email protected]/test');

这也不起作用.

这是错误信息:

{ MongoError: failed to connect to server [insight-shard-00-02-quhku.mongodb.net:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 18.194.163.64:27017]
at Pool.<anonymous> (U:WEBTProjectInsightQuiz
ode_modulesmongodb-corelib	opologiesserver.js:503:11)
at emitOne (events.js:115:13)
at Pool.emit (events.js:210:7)
at Connection.<anonymous> (U:WEBTProjectInsightQuiz
ode_modulesmongodb-corelibconnectionpool.js:326:12)
at Object.onceWrapper (events.js:318:30)
at emitTwo (events.js:125:13)
at Connection.emit (events.js:213:7)
at TLSSocket.<anonymous> (U:WEBTProjectInsightQuiz
ode_modulesmongodb-corelibconnectionconnection.js:245:50)
at Object.onceWrapper (events.js:316:30)
at emitOne (events.js:115:13)
at TLSSocket.emit (events.js:210:7)
at emitErrorNT (internal/streams/destroy.js:64:8)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
  name: 'MongoNetworkError',

消息:'第一次连接时无法连接到服务器 [insight-shard-00-02-quhku.mongodb.net:27017] [MongoNetworkError: connect ECONNREFUSED 18.194.163.64:27017]' }(node:4920) UnhandledPromiseRejectionWarning: Unhandled promise Rejection (rejection id: 1): MongoNetworkError: failed to connect to server [insight-shard-00-02-quhku.mongodb.net:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 18.194].163.64:27017](节点:4920)[DEP0018] 弃用警告:不推荐使用未处理的承诺拒绝.将来,未处理的承诺拒绝将以非零退出代码终止 Node.js 进程.

message: 'failed to connect to server [insight-shard-00-02-quhku.mongodb.net:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 18.194.163.64:27017]' }(node:4920) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): MongoNetworkError: failed to connect to server [insight-shard-00-02-quhku.mongodb.net:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 18.194.163.64:27017](node:4920) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

推荐答案

我也遇到了类似的问题,我能够通过在集群 -> 安全 -> IP 白名单下添加我的 IP 地址白名单来解决它.不要点击 my current ip address,只需在 google 上搜索我的 ip 并粘贴它.我希望它有效!

I also had a similar issue, and I was able to solve it by adding my white-listing my IP address under Clusters -> security -> IP Whitelist. Instead of clicking my current ip address, just search what's my ip on google and paste that instead.I hope it works!

这篇关于连接到 MongoDb Atlas 服务器时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 18:22