Connection to database DNS Error


Hi, I’m trying connect to the mongodb atlas on my spring boot application 2.7 but I’m getting this error.

Not working even on localhost with google dns resolver.

Caused by: com.mongodb.spi.dns.DnsException: DNS error

Does anyone know how to fix it?


Its your DNS server causing the error. Change DNS to google . If you are on a linux or mac

sudo nano /etc/resolv.conf

change name server to
This will work instantly. Also in your MongoDB clusters allow connection from anywhere. Once in production you can allow from your production APIs.

I had the same problem chatGTP gave me this solution. It worked for me.