本文介绍了连接到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:\WEBT\ProjectInsight\Quiz\node_modules\mongodb-core\lib\topologies\server.js:503:11)
at emitOne (events.js:115:13)
at Pool.emit (events.js:210:7)
at Connection.<anonymous> (U:\WEBT\ProjectInsight\Quiz\node_modules\mongodb-core\lib\connection\pool.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:\WEBT\ProjectInsight\Quiz\node_modules\mongodb-core\lib\connection\connection.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',

消息:在首次连接[MongoNetworkError:connect ECONNREFUSED 18.194.163.64:27017]时无法连接到服务器[insight-shard-00-02-quhku.mongodb.net:27017]'}(节点:4920)UnhandledPromiseRejectionWarning:未处理的承诺拒绝(拒绝ID:1):MongoNetworkError:首次连接[MongoNetworkError:连接ECONNREFUSED 18.194]时无法连接到服务器[insight-shard-00-02-quhku.mongodb.net:27017] .163.64:27017](节点:4920)[DEP0018] DeprecationWarning:已弃用未处理的承诺拒绝.将来,未处理的承诺拒绝将以非零退出代码终止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