使用MEAN堆栈连接到我的服务器时出现问题。 到今天为止,我一直没有连接问题,并且从那以后也没有进行任何代码更改,因此我对为什么突然之间无法连接感到困惑。
连接:
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);
});
响应:
[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)]: {} }
在终端中使用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
我的mongod像往常一样在单独的终端中运行。 是否有人对可能的问题以及如何根据错误响应进行修复有任何想法?
任何帮助都会很棒,谢谢!
答案 0 :(得分:3)
在相同情况下,您可以尝试做一些事情来帮助我。
答案 1 :(得分:0)
您遇到此错误的原因可能有以下三个。