Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 610 Vote(s) - 3.56 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to fix 'Error: querySrv EREFUSED' when connecting to MongoDB Atlas?

#11
This error occurs if you are not able to connect to mongoDB Atlas database. Your server runs successfully but you get this error while connecting to database. Make sure your internet connection is good and try again you won't see this error.
Reply

#12
```
Error: querySrv ESERVFAIL _mongodb._tcp.databasename-zcbag.mongodb.net
at QueryReqWrap.onresolve [as oncomplete] (dns.js:202:19) {
errno: 'ESERVFAIL',
code: 'ESERVFAIL',
syscall: 'querySrv',
hostname: '_mongodb._tcp.databasename-zcbag.mongodb.net'
}
```


----------
If the above code is your output then there is no error in your code. You have to check your network connection. Maybe you have to switch your network from the phone network to another or vice versa.


Reply

#13
## **"Not in the root folder" scenario:**

> Create a .env file in the **root directory** of your project.

[To see links please register here]


[![enter image description here][1]][1]

One scenario for this error is to create [dotenv][2] `.env` file --**NOT**-- in the `root folder` (Under `/src` for example).

Than this code:

```
const url = `mongodb+srv://${process.env.DB_USER}:${
process.env.DB_USER_PASSWORD
}@${process.env.DB_CLUSTER}.mongodb.net`;

console.log(url)
```
output:
```
mongodb+srv://undefined:[email protected]
```
So the `"undefined"` URL connection:
```
const client = new MongoClient(url);
```
Throw 3 warnings:

> (node:27240) UnhandledPromiseRejectionWarning: **Error: querySrv
> ENOTFOUND** _mongodb._tcp.undefined.mongodb.net
> at QueryReqWrap.onresolve [as oncomplete] (dns.js:207:19)

>(node:27240) UnhandledPromiseRejectionWarning: Unhandled promise
> rejection. This error originated either by throwing inside of an async
> function without a catch block, or by rejecting a promise which was
> not handled with .catch(). To terminate the node process on unhandled
> promise rejection, use the CLI flag `--unhandled-rejections=strict`
> (see

[To see links please register here]

).
> (rejection id: 1)

>(node:27240) [DEP0018] DeprecationWarning: Unhandled
> promise rejections are deprecated. In the future, promise rejections
> that are not handled will terminate the Node.js process with a
> non-zero exit code.

<hr>

**One more "close" scenario:**
`.env` in the root folder but the file is **empty**:

[![enter image description here][3]][3]
<hr>

### Solution

The **first step** to solve this issue is to `console.log(url)` and check if `process.env` returns the correct [Connection String][4].


<hr>

Related:
- **dotenv github readme**:

[To see links please register here]

- **Connect to a MongoDB Database Using Node.js
:**

[To see links please register here]



[1]:

[2]:

[To see links please register here]

[3]:

[4]:

[To see links please register here]

Reply

#14
In my case, it's mainly a DNS issue in mac, to resolve it, just add google DNS server under the DNS section in mac book pro settings:

```
8.8.8.8
4.4.4.4
```

[![enter image description here][1]][1]


[1]:
Reply

#15
In my case, the issue occurred because MongoDB paused my cluster due to over 4 months of inactivity. After I logged in to my account and resumed the activity of the cluster, the issue was immediately resolved.
Reply

#16
I solved mine by going into the MongoDB -> login -> databases -> connect -> connect your application (middle one) -> copy the code -> paste the code into the mongooseDB code in my .JS file:

const mongoose = require('mongoose');
require('dotenv/config');

mongoose
.connect(process.env.THE_MONGO_DB_URL_GOES_HERE_IN_DOTENV_FILE, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
})
.then(() => console.log("Database connected!"))
.catch(err => console.log(err));

const PostSchema = mongoose.Schema({
email: String,
password: String
}, {strict: false});

const DataEntry = mongoose.model('n26-users-collection', PostSchema);

module.exports = DataEntry;


Reply

#17
In my case it was throwing this error due mongodb cluster auto paused because of prolonged inactivity. I just resumed it, then it started properly.
Reply

#18
For the most part this error occurs when there is a mongodb driver and comnnection string mismatch. Ensure that use the conncetion string and its equivalent driver as specified in the Mongodb atlas connect section. Important Tip, dont use the latest mongodb driver. Use the previous version. You can acert conncetion issues easily.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through