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 8.8.8.8
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.