收到错误:querySrv ECONNREFUSED _mongodb._tcp.cluster0-9esxx.gcp.mongodb.net

时间:2020-06-25 15:19:15

标签: node.js mongodb express mongoose server

当我尝试运行节点应用程序时,我真的不知道为什么总是收到此错误“错误:querySrv ECONNREFUSED _mongodb._tcp.cluster0-9esxx.gcp.mongodb.net”。是来自服务器还是互联网不佳? 这是database.js文件

const mongoose = require("mongoose");

const connectDB = async () => {
    try {
        const conn = await mongoose.connect(process.env.MONGO_URI, {
            // to avoid warnings in the console
            useNewUrlParser: true,
            useUnifiedTopology: true,
            useFindAndModify: false,
        });

        console.log(`mongoDB connected ${conn.connection.host}`);
    } catch (err) {
        console.error(err);
        // stop the process
        process.exit(1);
    }
};

module.exports = connectDB;

0 个答案:

没有答案