MongoDB Atlas连接错误“无法连接到服务器...” [英] MongoDB Atlas connection error "failed to connect to server..."

查看:459
本文介绍了MongoDB Atlas连接错误“无法连接到服务器...”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用mongoose与mongodb进行连接,但是会引发错误。
这是我的代码:

I am trying to perform a connection to mongodb using mongoose but it throws an error. Here is my code:

mongoose.connect("mongodb+srv://username:password@cluster0-bocic.mongodb.net/test?retryWrites=true", {useNewUrlParser: true})
    .then(()=>console.log("Database connected..."))
    .catch(err=>console.log(err));

这是错误:

[0] { MongoNetworkError: failed to connect to server [cluster0-shard-00-01-bocic
.mongodb.net:27017] on first connect [MongoNetworkError: connection 5 to cluster
0-shard-00-01-bocic.mongodb.net:27017 closed]
[0]     at Pool.<anonymous> (C:\Users\Med\Desktop\jutsuapp\myapp\node_modules\mo
ngodb-core\lib\topologies\server.js:431:11)
[0]     at Pool.emit (events.js:182:13)
[0]     at connect (C:\Users\Med\Desktop\jutsuapp\myapp\node_modules\mongodb-cor
e\lib\connection\pool.js:557:14)
[0]     at callback (C:\Users\Med\Desktop\jutsuapp\myapp\node_modules\mongodb-co
re\lib\connection\connect.js:109:5)
[0]     at runCommand (C:\Users\Med\Desktop\jutsuapp\myapp\node_modules\mongodb-
core\lib\connection\connect.js:129:7)
[0]     at Connection.errorHandler (C:\Users\Med\Desktop\jutsuapp\myapp\node_mod
ules\mongodb-core\lib\connection\connect.js:321:5)
[0]     at Object.onceWrapper (events.js:273:13)
[0]     at Connection.emit (events.js:182:13)
[0]     at TLSSocket.<anonymous> (C:\Users\Med\Desktop\jutsuapp\myapp\node_modul
es\mongodb-core\lib\connection\connection.js:350:12)
[0]     at Object.onceWrapper (events.js:273:13)
[0]     at TLSSocket.emit (events.js:182:13)
[0]     at _handle.close (net.js:610:12)
[0]     at TCP.done (_tls_wrap.js:386:7)
[0]   name: 'MongoNetworkError',
[0]   errorLabels: [ 'TransientTransactionError' ],
[0]   [Symbol(mongoErrorContextSymbol)]: {} }


推荐答案

我必须解决相同的问题:在最近三天内,我的应用程序(node.js,express,mongoose,graphql)已连接到mongoDB(在云中),而没有任何问题,但今天我得到了:

I got to solve the same problem: in the last three days my applications (node.js, express, mongoose, graphql) got connected to the mongoDB (in the cloud) whithout any problem, but today I got:

错误:MongoNetworkError:无法连接到服务器[cluster0-shard-00-00-cpkkj.mongodb.net:27017]第一次连接时[MongoNetworkError:与cluster0-shard-00-00-cpkkj.mongodb.net:27017已关闭的连接5]

我验证了IP我的电脑,那是它:它已经更改,并且与我添加到白名单中的IP不再相同,因此我添加了新IP,问题得以解决。

I verified the IP of my PC and that's it: it has changed and is not more the same IP I added to the Whitelist, so I added the new one and the problem was solved.

这篇关于MongoDB Atlas连接错误“无法连接到服务器...”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆