Error: queryTxt ETIMEOUT cluster0.dxzhf.mongodb.net
Error: queryTxt ETIMEOUT cluster0.dxzhf.mongodb.net
我正在尝试 npm 启动我的后端,但我在连接到 mongodb atlas 时遇到错误。
这是我的 index.js 代码:
import express from 'express';
import bodyParser from 'body-parser';
import mongoose from 'mongoose';
import cors from 'cors';
const app = express();
app.use(bodyParser.json({limit: "30mb", extended: true}));
app.use(bodyParser.urlencoded({limit: "30mb", extended: true}));
app.use(cors());
const CONNECTION_URL = "mongodb+srv://Danishbukhari:(mypassword)@cluster0.dxzhf.mongodb.net/myFirstDatabase?retryWrites=true&w=majority"
const PORT = process.env.PORT || 5000;
mongoose.connect(CONNECTION_URL, { useNewUrlParser: true})
.then(() => app.listen(PORT, () => console.log(`Server running on port: ${PORT}`)))
.catch((error) => console.log(error.message) )
我的 package.json 就像:
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"start": "nodemon index.js"
},
"author": "Danish",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.1",
"cors": "^2.8.5",
"express": "^4.17.2",
"mongodb": "^4.2.2",
"mongoose": "^6.1.2",
"nodemon": "^2.0.15"
}
}
我也已将我的 IP 地址列入白名单
请告诉我如何解决这个问题:(
我遇到了这个问题,将 DNS 更改为 8.8.8.8
对我有用。
但在此之前,请确保:
- 检查您的网络连接。
- 关闭 VPN。
mongoDB
中的 IP 白名单
- 在
mongoDB
中检查您的凭据
祝你好运 ;-) 如果仍有问题,请查看 link
我正在尝试 npm 启动我的后端,但我在连接到 mongodb atlas 时遇到错误。 这是我的 index.js 代码:
import express from 'express';
import bodyParser from 'body-parser';
import mongoose from 'mongoose';
import cors from 'cors';
const app = express();
app.use(bodyParser.json({limit: "30mb", extended: true}));
app.use(bodyParser.urlencoded({limit: "30mb", extended: true}));
app.use(cors());
const CONNECTION_URL = "mongodb+srv://Danishbukhari:(mypassword)@cluster0.dxzhf.mongodb.net/myFirstDatabase?retryWrites=true&w=majority"
const PORT = process.env.PORT || 5000;
mongoose.connect(CONNECTION_URL, { useNewUrlParser: true})
.then(() => app.listen(PORT, () => console.log(`Server running on port: ${PORT}`)))
.catch((error) => console.log(error.message) )
我的 package.json 就像:
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"start": "nodemon index.js"
},
"author": "Danish",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.1",
"cors": "^2.8.5",
"express": "^4.17.2",
"mongodb": "^4.2.2",
"mongoose": "^6.1.2",
"nodemon": "^2.0.15"
}
}
我也已将我的 IP 地址列入白名单 请告诉我如何解决这个问题:(
我遇到了这个问题,将 DNS 更改为 8.8.8.8
对我有用。
但在此之前,请确保:
- 检查您的网络连接。
- 关闭 VPN。
mongoDB
中的 IP 白名单
- 在
mongoDB
中检查您的凭据
祝你好运 ;-) 如果仍有问题,请查看 link