Node.js 无法连接到MongoDB群集
我找不到与我的问题有关的答案 这是我的Node.js 无法连接到MongoDB群集,node.js,mongodb,mongoose,mongodb-atlas,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 () =>
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;
我添加了允许从任何地方访问
,作为Atlas MongoDB上IP的白名单选项
我创建了新的集群来验证MongoDB上没有任何东西被破坏
就在两天前,它还可以工作,但现在根本不行
所有软件包都是最新的,Node
和npm
本身也是最新的
MongoDB connected
从不打印
我在不同的网络上测试过
不知道从这里去哪里。你能展示你的
db.js
@Mikecan你能展示你的db.js
@Mike吗