I had the same issue as the OP and it has been brought up many times here and on SF.

In digging in to my situation I was running a 3 node replicaset with docker-compose in docker for Mac and trying to connect with Compass. Was getting the never ending ENOTFOUND <dns_service_name>.

When adding all 3 localhost entries to Compass with different ports I noticed in the replicaset logs that Compass actually connected to all 3 nodes using localhost but then changed the connection to dns_service_name and disconnected, giving the ENOTFOUND error. The replicasets connect to each other using that dns_service_name. I tried modifying the replicaset init to reflect localhost and also 127.0.0.1 and then they couldnt connect to each other.

Perhaps there is a way to create a new replicaset init file that enables localhost in Compass but dns_service_name between replicasets? IDK

I ended up adding all 3 dns_service_name entries to my etc/hosts file on my MacOS dev host.

127.0.0.1 rs101
127.0.0.1 rs102
127.0.0.1 rs103

Then had to flush the dns with this
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

After all of that I connected with this in Compass:

mongodb://rs101:27017,rs102:28017,rs103:29017/?replicaSet=rs&ssl=false&authMechanism=DEFAULT&serverSelectionTimeoutMS=2000

There are other ways to do this such as adding a Nginx Reverse Proxy to the Docker-Compose file but this was quicker.

Hope this helps someone save a lot of wasted hours debugging that ENOTFOUND error.

1 Like