Node.js和MongoDB Atlas猫鼬连接错误

时间:2018-09-30 22:27:09

标签: 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:与群集的连接5 ... 27017在TLSSocket中关闭。 ...

我该如何解决?

1 个答案:

答案 0 :(得分:3)

已解决-检查IP白名单!