How do I fix the MongoDB error "DNSHostNotFound: Failed to look up service"?

When connecting to a MongoDB Managed Database from your local machine, you may get the following error:

DNSHostNotFound: Failed to look up service “_mongodb._tcp.<MongoDB hostname>”

This error can occur when you use your internet service provider’s default DNS server, which might not support the SRV lookups used by the DNS seed list connection string format.

To fix this error, you can try using a public DNS server, such as Google’s 8.8.8.8, instead.