连接到 MONGODB 但未连接"/>
尝试连接到 MONGODB 但未连接
我正在尝试连接到我在 MongoDB 中的数据库,但它没有连接,我正在使用这个代码(index.js)
const express = require('express');
const mongoose = require('mongoose');
let app = null;
let port = null;
let MONGO_URL = null;
const initVar = async () => {
port = 9000;
MONGO_URL = "mongodb+srv://mc3453:[email protected]/customer?retryWrites=true&w=majority";
app = express();
};
mongoose.set('strictQuery', true);
const connectDB = async () => {
try {
await mongoose.connect(MONGO_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
console.log('MongoDB connected');
} catch (error) {
console.log(error);
}
};
const listentoPort = async () => {
app.listen(port, async () => {
console.log(`Server is running on port ${port}`);
});
};
initVar().then(() => {
listentoPort().then(() => {
connectDB();
});
});
连接字符串为:
mongodb+srv://mc3453:<password>@unify.dyadwbb.mongodb/?retryWrites=true&w=majority
我得到的错误是:
Error: queryTxt ETIMEOUT unify.dyadwbb.mongodb
at QueryReqWrap.onresolve [as oncomplete] (node:internal/dns/promises:251:17) {
errno: undefined,
code: 'ETIMEOUT',
syscall: 'queryTxt',
hostname: 'unify.dyadwbb.mongodb'
}
我什至添加了我的 IP 地址,但每次我切换回该网站时,它都说您的 IP 地址不存在,但我又重新添加了它
我该如何解决这个问题请帮我解决这个问题,我是新手请帮帮我
回答如下:更多推荐
尝试连接到 MONGODB 但未连接
发布评论