Search code examples
mongodbdns

Connecting to MongoDB via a hotspot is not working


I am trying to connect to my MongoDB Atlas cluster via a phone hotspot. My IP is in the Access List and I'm able to connect on a normal internet connection at home or in the office, but it doesn't work when I'm on a phone hotspot. The connection just times out.


Solution

  • Some cell carriers automatically connect you to a DNS server that doesn't support SRV records. That means using the mongodb+srv protocol while running on a hotspot from your phone using one of these carriers will fail. In my experience it causes the connection to timeout.

    This can be solved 2 ways:

    1. Use an alternative DNS such as Google's at 8.8.8.8 and 8.8.4.4
    2. Use the standard mongodb:// protocol in your connection string. This connection string will be longer and more verbose.

    If you go with option 1, Double check these IPs before using them. They probably will never change, but you'd never want to use untrusted DNS server so better to double check.

    Also note that in Windows 11, I had to change my DNS and then restart the machine. I read you could run ipconfig /flushdns but that had no effect for me.