MongoDB 连接错误:MongoNetworkError:托管在循环上时

sim*_*mon 4 cyclic mongoose mongodb node.js

我有一个托管在循环上的 NodeJs API。早些时候一切工作正常,但我用尽了我的免费层 API 请求,我的应用程序被暂停,然后不得不升级。从那时起我就一直遇到这个错误

 MongoDB connection error: MongoNetworkError: 805C21D67D7F0000:error:0A000438:SSL routines:ssl3_read_bytes:tlsv1 alert internal error:ssl/record/rec_layer_s3.c:1586:SSL alert number 80

    at connectionFailureError (/var/task/node_modules/mongoose/node_modules/mongodb/lib/cmap/connect.js:367:20)
    at TLSSocket.<anonymous> (/var/task/node_modules/mongoose/node_modules/mongodb/lib/cmap/connect.js:290:22)
    at Object.onceWrapper (node:events:629:26)
    at TLSSocket.emit (node:events:514: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: 805C21D67D7F0000:error:0A000438:SSL routines:ssl3_read_bytes:tlsv1 alert internal error:ssl/record/rec_layer_s3.c:1586:SSL alert number 80
  ] {
    library: 'SSL routines',
    reason: 'tlsv1 alert internal error',
    code: 'ERR_SSL_TLSV1_ALERT_INTERNAL_ERROR'
  },
  connectionGeneration: 2,
  [Symbol(errorLabels)]: Set(1) { 'ResetPool' }
}

Run Code Online (Sandbox Code Playgroud)

我已经尝试了一切,我以为我的 mongo 免费层已经用完了。我升级了,没用。我更新了我的猫鼬包,我尝试在网上搜索但找不到任何东西。这就是我在index.js中连接到数据库的方式 //在监听之前连接到数据库

connectDB().then(() => {
  app.listen(PORT, () => {
    console.log(`App listening on port ${PORT}`);
  });
});
Run Code Online (Sandbox Code Playgroud)

这是我的 connectDB 函数

const mongoose = require("mongoose");

const connectDB = async () => {
  try {
    await mongoose.connect(process.env.MONGO_URL, {
      useNewUrlParser: true,
      useUnifiedTopology: true,
    });
    console.log("MongoDB connected");
  } catch (error) {
    console.error("MongoDB connection error:", error);
  }
};

module.exports = connectDB;
Run Code Online (Sandbox Code Playgroud)

到底是什么导致了该错误以及我该如何纠正

Jef*_*f R 7

错误ERR_SSL_TLSV1_ALERT_INTERNAL_ERROR(上面)可能是由于未在 Mongo Atlas 中将您的 IP 列入白名单而导致的。确保您没有被网络访问设置阻止!这有点误导,因为它是一个“ssl 错误”,但它实际上只是告诉您 SSL 握手无法完成(因为您的 IP 未列入白名单)。

因此,这至少是解决此错误的一种可能的方法。