Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't connect Mongo shell to Mongo Atlas M0 using mongodb+srv

Tags:

mongodb

I am trying to connect to my MongoDB Atlas Cloud cluster via the mongo+srv connection like so:

mongo "mongodb+srv://cluster0-mhzdc.mongodb.net/test" --username myuser

I am getting this response:

DNSHostNotFound: Failed to look up service "_mongodb._tcp.cluster0-mhzdc.mongodb.net": Undefined error: 0
try 'mongo --help' for more information

I am using the following version of Mongo client:

mongo --version
MongoDB shell version v4.0.5
git version: 3739429dd92b92d1b0ab120911a23d50bf03c412
allocator: system
modules: none
build environment:
    distarch: x86_64
    target_arch: x86_64

I can't find any resolution online. Any ideas what's wrong? Is this a bug in the given version of the Mongo shell client?

like image 906
pkout Avatar asked Jan 27 '23 09:01

pkout


1 Answers

It looks like bug 34117, still unresolved:

https://jira.mongodb.org/browse/SERVER-34117

To work around the bug check if you have a DNS resolver active on your notebook. On windows:

ipconfig /displayDNS

to see the current DNS resolver cache. You might even try to erase the cache with the command:

ipconfig /flushdns

and retry. If you are working on linux ubuntu try the command:

named -v

to check if the DNS resolver software is already installed. If not:

sudo apt update
sudo apt install bind9 bind9utils bind9-doc bind9-host

to install the needed packages, then start the service:

sudo systemctl start bind9

and retry.

On Mac OSX, the command is:

sudo killall -HUP mDNSResponder;sudo killall mDNSResponderHelper;sudo dscacheutil -flushcache
like image 73
Saxon Avatar answered Jan 31 '23 01:01

Saxon