Elastic Beanstalk上的Web服务器与MongoDB Atlas上的数据库服务器连接出错

问题描述 投票:1回答:1

我正在尝试将我的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.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白名单中,因为我已经在弹性beantalk上进入服务器,并从那里直接连接到Atlas上的Mongo服务器。问题出在代码中,尽管我似乎看不到它。

node.js mongodb amazon-web-services mongoose amazon-elastic-beanstalk
1个回答
0
投票

我有同样的问题。将0.0.0.0/0添加到IP白名单。

© www.soinside.com 2019 - 2024. All rights reserved.