无法连接到MongoDB集群

时间:2019-08-17 10:45:10

标签: node.js mongodb mongoose mongodb-atlas

我找不到与我的问题有关的答案。

这是我的db.js

// for mongoDB connection
const mongoose = require("mongoose");
// require the directory
const config = require("config");
// get all contents of JSON file
const db = config.get("mongoURI");

const connectDb = async () => {
  try {
    // outputs correct string with correct credentials, as seen in Mongodb
    console.log(db);

    // hangs here
    await mongoose.connect(db, {
      useNewUrlParser: true,
      useCreateIndex: true,
      useFindAndModify: false
    });

    // never reached
    console.log("Mongo DB connected");
  } catch (err) {
    // never reached either, no error is thrown
    console.log(err.message);
    //exit if failure
    process.exit(1);
  }
};

module.exports = connectDb;

我已将allow access from anywhere添加为Atlas MongoDB上IP的白名单选项。

我已经创建了新的集群,以验证MongoDB上是否没有任何损坏。

它实际上只是在两天前就工作了,现在根本就没有。

所有软件包以及Nodenpm本身都是最新的

MongoDB connected从不打印。

我已经在不同的网络上进行了测试。

不确定从这里要去哪里。

0 个答案:

没有答案
相关问题