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

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.

Verify the format and values in the connection string for typos or formatting errors.
Prepend your database client command to the connection string.
Remove the _id field from your JSON data so MongoDB can automatically generate unique _id values for each document during import.