Node.js 和 MongoDB Atlas Mongoose 连接错误

标签 node.js mongodb mongoose mongodb-atlas

我正在尝试将 MongoDB atlas 实例连接到 nodejs/express 服务器:

const mongoose = require("mongoose");

const dbURI =
 "mongodb+srv://(url copied from atlas connect)";

const options = {
  useNewUrlParser: true,
  dbName: "data"
};

mongoose.connect(dbURI, options).then(
 () => {
   console.log("Database connection established!");
 },
 err => {
   console.log("Error connecting Database instance due to: ", err);
 }
);

但我一直收到以下错误:

MongoNetworkError: connection 5 to cluster ... 27017 closes at TLSSocket. ...

我该如何解决这个问题?

最佳答案

已解决——检查IP白名单!

关于Node.js 和 MongoDB Atlas Mongoose 连接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52582674/

相关文章:

Java Future - Spring Authentication 在 AuditorAware 中为空

javascript - 热重载期间识别的模型,仅在服务器重新启动后失败

javascript - NodeJS async.parallel 成功被调用两次?

asynchronous - Node.js:您什么时候知道异步任务集合何时完成?

javascript - 如何检查文档/文档快照中是否存在某个字段?

node.js - 为什么我的应用程序在端口 80 而不是端口 3000 上监听,因为我将它设置为在 docker 容器中运行?

linux - 使用日期的 Mongo shell 查询

java - MongoDB-Java : Not operator and regular expressions

node.js - Mongoose 将此字段设置为 true 其他字段将为 false

node.js - 创建一个支持回调和 promise 的 Mongoose 插件