Error: querySrv ECONNREFUSED

I’m using Ubuntu in WSL2 in Windows 11.
Node v18.18.2 with Mongoose

I am in China and use Astrill VPN.

My connection string is:

DATABASE_URI=mongodb+srv://<my user name>:<my password>@my DB name>

Config file:

  try {
    const conn = await mongoose.connect(process.env.DATABASE_URI, {
      useUnifiedTopology: true,
      useNewUrlParser: true,

    console.log(`Database connected: ${}`);
  } catch (error) {
    console.log(`Error: ${error.message}`);

When I do ‘npm run server’, I see this:

[nodemon] starting `node app.js`
App running on port 5000
Error: querySrv ECONNREFUSED
[nodemon] app crashed - waiting for file changes before starting...

I’ve tried turning VPN on and off, switching VPN routes, all Windows firewalls are turned off, I am using the nearest cluster (Hong Kong), my DNS servers are set to Google.

I am able to connect when setting Astrill to stealth mode - otherwise, I keep getting this error.

While stealth mode is functional, I’d like to know if there is a better solution to this issue.

Thanks for any pointers.

Hi @Seb_Lex - Welcome to the community.

Whilst I do understand you’ve tried using Google DNS servers, it seems like (At least based off the information provided) a possible configuration issue with the VPN you are using since it works in “stealth mode”. You can maybe try doing a nslookup against from stealth mode and outside of stealth mode to see what the output is for troubleshooting purposes although I can’t say what configuration(s) / changes would be required here to be able to connect using Astrill VPN.

Is the use case requiring VPN usage and if so, have you considered testing with other VPN providers to see if the same errors are generated?

From the above, it sounds like there isn’t anything particularly wrong with the Atlas network settings / cluster since you’re able to connect as well.


1 Like