Home > Software engineering >  Error: queryTxt ETIMEOUT cluster0.dxzhf.mongodb.net
Error: queryTxt ETIMEOUT cluster0.dxzhf.mongodb.net

Time:12-21

Am trying to npm start my backend but I am having the error with connection to mongodb atlas. here is my index.js code:

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) )

and my package.json be like:

{
  "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"
  }
}

my Mongodb atlas connection page

I have also whitelisted my IP adress please tell my how to resolve this issue :(

CodePudding user response:

I had this issue and Changing DNS to 8.8.8.8 worked for me.

But before this, make sure that:

  1. Check your connection.
  2. Turn off VPN.
  3. IP whitelist in mongoDB
  4. Check your credentials in mongoDB

Good Luck ;-) If still have issue check it out link

  • Related