[英]Error connecting web server on Elastic Beanstalk with database server on MongoDB Atlas
我正在嘗試將 Elastic Beanstalk 上的 web 服務器與 MongoDB Atlas 上的數據庫服務器連接,但不知何故我收到以下錯誤
Listening at http://:::3001
Unable to connect to the mongodb instance. Error: { MongoNetworkError: failed to connect to server [<server>.mongodb.net:27017] on first connect [MongoNetworkError: connection 5 to <server>.mongodb.net:27017 closed]
at Pool.<anonymous> (/var/app/current/node_modules/mongodb-core/lib/topologies/server.js:431:11)
at Pool.emit (events.js:198:13)
at connect (/var/app/current/node_modules/mongodb-core/lib/connection/pool.js:557:14)
at callback (/var/app/current/node_modules/mongodb-core/lib/connection/connect.js:109:5)
at runCommand (/var/app/current/node_modules/mongodb-core/lib/connection/connect.js:129:7)
at Connection.errorHandler (/var/app/current/node_modules/mongodb-core/lib/connection/connect.js:321:5)
at Object.onceWrapper (events.js:286:20)
at Connection.emit (events.js:198:13)
at TLSSocket.<anonymous> (/var/app/current/node_modules/mongodb-core/lib/connection/connection.js:350:12)
at Object.onceWrapper (events.js:286:20)
at TLSSocket.emit (events.js:198:13)
at _handle.close (net.js:606:12)
at TCP.done (_tls_wrap.js:388:7)
name: 'MongoNetworkError',
errorLabels: [ 'TransientTransactionError' ],
[Symbol(mongoErrorContextSymbol)]: {} }
Listening at http://:::3001
(node:11482) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
Listening at http://:::3001
我正在使用 mongoose 如下
mongoose.connect('mongodb+srv://<UserName>:<Password>@<cluster>.mongodb.net/test?retryWrites=true&w=majority',
{ useNewUrlParser: true, useUnifiedTopology: true })
.catch(function (reason) {
console.log('Unable to connect to the mongodb instance. Error: ', reason);
});
問題不在 MongoDB Atlas 上的 IP 白名單中,因為我已經通過 ssh 連接到 elastic beanstalk 上的服務器,並從那里直接連接到 Atlas 上的 Mongo 服務器。 問題出在代碼中,盡管我似乎看不到它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.