Complete class w/o Compass using pymongo driver instead?

Greetings… Erik from USA here.

I will (or am, somewhat already) dealing with a MongoDB at work, but haven’t really worked with MongoDB before…

For unknown reasons, I was not able to install Compass on my local machine. (installer launches, but then just quits w/o any error indication. It’s an older machine, I am looking for a workaround.)

Ultimately I need to interact with MongoDB via Python, anyway.

I created my own Atlas instance, and the following Code will connect to that and get my DB names:

import pymongo, urllib, pdb

user = 'username'
pw = 'myPassword'
host = "<something>"

path = "/test?retryWrites=true"
dbConn_tmpl = "mongodb+srv://{}:{}@{}{}"
pwEnc = urllib.parse.quote_plus(pw)
dbConn = dbConn_tmpl.format(user, pwEnc, host, path)

print("Connecting to:", dbConn)
client = pymongo.MongoClient(dbConn)
for db in list(client.list_databases()):

This will print out:

Connecting to: mongodb+srv://
{'name': 'db0', 'sizeOnDisk': 32768.0, 'empty': False}
{'name': 'admin', 'sizeOnDisk': 229376.0, 'empty': False}
{'name': 'local', 'sizeOnDisk': 716402688.0, 'empty': False}

So, that seems to work as expected. I was hoping to do this class just using pymongo DB driver instead of Compass application (since I am ultimately going to be interacting with DB via Python, anyway).

If I substitute the following values for my own user/pass/atlas instance:

user = 'm001-student'
pw = 'm001-mongodb-basics'
host = ""

and try the program again, hoping to talk to our class DB, I get the following errors:

Connecting to: mongodb+srv://m001-student:m001-mongodb-basics@cluster0-shard-00-
Traceback (most recent call last):
  File "C:\Python36\lib\site-packages\pymongo\", line 287, in _get_
    results = resolver.query('_mongodb._tcp.' + hostname, 'SRV')
  File "C:\Python36\lib\site-packages\dns\", line 1102, in query
  File "C:\Python36\lib\site-packages\dns\", line 1002, in query
    raise NXDOMAIN(qnames=qnames_to_try, responses=nxdomain_responses)
dns.resolver.NXDOMAIN: None of DNS query names exist: _mongodb._tcp.cluster0-sha,

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "", line 35, in <module>
    client = pymongo.MongoClient(dbConn)
  File "C:\Python36\lib\site-packages\pymongo\", line 494, in __i
    res = uri_parser.parse_uri(entity, port, warn=True)
  File "C:\Python36\lib\site-packages\pymongo\", line 399, in parse
    nodes = _get_dns_srv_hosts(fqdn)
  File "C:\Python36\lib\site-packages\pymongo\", line 289, in _get_
    raise ConfigurationError(str(exc))
pymongo.errors.ConfigurationError: None of DNS query names exist: _mongodb._tcp., _mongodb._tcp.cluster0-shard-00-00-jxeq<mycompany>.com.

Is there some way somebody could help me connect via Python? I don’t know what the issue with installing Compass is, but I suspect this may be easier to solve than that install.


It may be useful to know that:


will return replies as expected.

I can connect by compass or mongo.exe. With pymongo, always timeout after 30s, what is the problem?