【问题标题】:Connect ECONNREFUSED 127.0.0.1:27017 in Mongodb在 Mongodb 中连接 ECONNREFUSED 127.0.0.1:27017
【发布时间】:2022-12-30 02:42:13
【问题描述】:

您好,我是 MongoDB 的新手。我正在尝试使用 'mongodb://localhost:27017' 连接到 MongoDb 但未连接。但是我尝试使用它正在运行的 MongoDb Compass 和 mongosh shell 命令输入。 错误代码是

node app.js
node:internal/process/promises:288
triggerUncaughtException(err, true /* fromPromise */);
            ^

AssertionError [ERR_ASSERTION]: null == MongoServerSelectionError: connect ECONNREFUSED ::1:27017
at Timeout._onTimeout (C:\Users\kokophone\Documents\MEGAsync\Mystudy\Web\Udemy\Angela Bootcamp\Mgphone One\MangoDB\FruitProject\node_modules\mongodb\lib\sdam\topology.js:292:38)
at listOnTimeout (node:internal/timers:564:17)
at process.processTimers (node:internal/timers:507:7) {
[Symbol(errorLabels)]: Set(0) {},
code: undefined,
reason: TopologyDescription {
commonWireVersion: 0,
compatible: true,
heartbeatFrequencyM...
at C:\Users\kokophone\Documents\MEGAsync\Mystudy\Web\Udemy\Angela Bootcamp\Mgphone One\MangoDB\FruitProject\app.js:15:10
at C:\Users\kokophone\Documents\MEGAsync\Mystudy\Web\Udemy\Angela Bootcamp\Mgphone One\MangoDB\FruitProject\node_modules\mongodb\lib\utils.js:349:66 {
generatedMessage: true,
code: 'ERR_ASSERTION',
actual: null,
expected: MongoServerSelectionError: connect ECONNREFUSED ::1:27017
at Timeout._onTimeout (C:\Users\kokophone\Documents\MEGAsync\Mystudy\Web\Udemy\Angela Bootcamp\Mgphone One\MangoDB\FruitProject\node_modules\mongodb\lib\sdam\topology.js:292:38)
at listOnTimeout (node:internal/timers:564:17)
at process.processTimers (node:internal/timers:507:7) {
reason: TopologyDescription {
type: 'Unknown',
servers: Map(1) {
        'localhost:27017' => ServerDescription {
address: 'localhost:27017',
type: 'Unknown',
hosts: [],
passives: [],
arbiters: [],
tags: {},
minWireVersion: 0,
maxWireVersion: 0,
roundTripTime: -1,
lastUpdateTime: 2313988,
lastWriteDate: 0,
error: MongoNetworkError: connect ECONNREFUSED ::1:27017
at connectionFailureError (C:\Users\kokophone\Documents\MEGAsync\Mystudy\Web\Udemy\Angela Bootcamp\Mgphone One\MangoDB\FruitProject\node_modules\mongodb\lib\cmap\connect.js:387:20)
at Socket.<anonymous> (C:\Users\kokophone\Documents\MEGAsync\Mystudy\Web\Udemy\Angela Bootcamp\Mgphone One\MangoDB\FruitProject\node_modules\mongodb\lib\cmap\connect.js:310:22)
at Object.onceWrapper (node:events:628:26)
at Socket.emit (node:events:513:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
cause: [Error],
[Symbol(errorLabels)]: [Set]
          },
topologyVersion: null,
setName: null,
setVersion: null,
electionId: null,
logicalSessionTimeoutMinutes: null,
primary: null,
me: null,
          '$clusterTime': null
        }
      },
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: null,
maxElectionId: null,
maxSetVersion: null,
commonWireVersion: 0,
logicalSessionTimeoutMinutes: null
    },
code: undefined,
[Symbol(errorLabels)]: Set(0) {}
  },
operator: '=='
}

Node.js v18.12.1

请帮帮我。

【问题讨论】:

  • MongoDB 是否绑定了 IPv6 环回地址?也许你需要尝试127.0.0.1而不是localhost
  • 你需要在 mongodb 网络访问面板中添加你的 ip 地址。
  • mongodb://127.0.0.1:27017 使用它作为连接字符串。

标签: node.js node-mongodb-native


【解决方案1】:

将 localhost 更改为 0.0.0.0。在源代码中。

const url = "mongodb://localhost:27017/"; const client = new MongoClient(url);

const url = "mongodb://0.0.0.0:27017/"; const client = new MongoClient(url);

【讨论】:

    猜你喜欢
    • 2020-04-10
    • 2022-11-09
    • 1970-01-01
    • 2021-04-15
    • 2018-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-01
    相关资源
    最近更新 更多