[英]Unable to connect to Mongodb.atlas cluster using MEAN stack
Having issues connecting to my server using the MEAN stack.使用 MEAN 堆栈连接到我的服务器时出现问题。 I had no problems connecting until today and have not made code changes since so I am baffled on why all a sudden I am not able to connect.
直到今天我都没有连接问题,并且从那以后没有进行代码更改,所以我对为什么突然无法连接感到困惑。
Connection:联系:
mongoose.connect("mongodb+srv://theller5567:" + process.env.MONGO_ATLAS_PW + "@cluster0-efzkv.mongodb.net/node-angular", { useNewUrlParser: true })
.then(() => {
console.log("Connected to database!");
})
.catch((error) => {
console.log("Connection failed!", error);
});
Response:回复:
[nodemon] starting `node server.js`
Connection failed! { MongoNetworkError: failed to connect to server
[cluster0-shard-00-01-efzkv.mongodb.net:27017] on first connect
[MongoNetworkError: getaddrinfo ENOTFOUND cluster0-shard-00-01-
efzkv.mongodb.net cluster0-shard-00-01-efzkv.mongodb.net:27017]
at Pool.<anonymous> (/Users/Travis/Desktop/Github_Repos/OMNI-INC/Omni-
pl/node_modules/mongodb-core/lib/topologies/server.js:564:11)
at Pool.emit (events.js:182:13)
at Connection.<anonymous> (/Users/Travis/Desktop/Github_Repos/OMNI-INC/Omni-
pl/node_modules/mongodb-core/lib/connection/pool.js:317:12)
at Object.onceWrapper (events.js:273:13)
at Connection.emit (events.js:182:13)
at TLSSocket.<anonymous> (/Users/Travis/Desktop/Github_Repos/OMNI-INC/Omni-
pl/node_modules/mongodb-core/lib/connection/connection.js:246:50)
at Object.onceWrapper (events.js:273:13)
at TLSSocket.emit (events.js:182:13)
at emitErrorNT (internal/streams/destroy.js:82:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
at process._tickCallback (internal/process/next_tick.js:63:19)
name: 'MongoNetworkError',
errorLabels: [ 'TransientTransactionError' ],
[Symbol(mongoErrorContextSymbol)]: {} }
Response from connecting using MongoShell in terminal:在终端中使用 MongoShell 进行连接的响应:
connecting to: mongodb+srv://cluster0-efzkv.mongodb.net/test
2018-09-21T13:22:28.817-0400 I NETWORK [js] Starting new replica set monitor
for Cluster0-shard-0/cluster0-shard-00-02-efzkv.mongodb.net.:27017,cluster0-
shard-00-00-efzkv.mongodb.net.:27017,cluster0-shard-00-01-
efzkv.mongodb.net.:27017
2018-09-21T13:23:22.276-0400 W NETWORK [js] Unable to reach primary for set
Cluster0-shard-0
2018-09-21T13:23:22.276-0400 I NETWORK [js] Cannot reach any nodes for set
Cluster0-shard-0. Please check network connectivity and the status of the
set. This has happened for 1 checks in a row.
2018-09-21T13:23:22.280-0400 E QUERY [js] Error: connect failed to replica
set Cluster0-shard-0/cluster0-shard-00-02-efzkv.mongodb.net.:27017,cluster0-
shard-00-00-efzkv.mongodb.net.:27017,cluster0-shard-00-01-
efzkv.mongodb.net.:27017 :
connect@src/mongo/shell/mongo.js:257:13
@(connect):1:6
exception: connect failed
I have mongod running in a separate terminal like always.我像往常一样在单独的终端中运行 mongod。 Does anyone have any ideas on what might be the issue and how to fix based on the error response?
有没有人对可能出现的问题以及如何根据错误响应进行修复有任何想法?
Any help would be great, thank you!任何帮助都会很棒,谢谢!
there are a few things you could try which helped me out in the same situation.在同样的情况下,您可以尝试一些帮助我解决问题的方法。
There might be three reasons why you facing this error.您面临此错误的原因可能有三个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.