How to fix ‘Error: querySrv EREFUSED’ when connecting to MongoDB Atlas?

If you’re encountering this error try to use the older connection string for Node.js 2.2.12 or later:

mongodb://<username>:<password>@main-shard-00-00-03xkr.mongodb.net:27017,main-shard-00-01-03xkr.mongodb.net:27017,main-shard-00-02-03xkr.mongodb.net:27017/main?ssl=true&replicaSet=Main-shard-0&authSource=admin&retryWrites=true

According to MongoDB, SRV is possibly not working due to Mongoose.

Leave a Comment