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>.mongodb.net"

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)
print("list_databases():")
for db in list(client.list_databases()):
    print(db)

This will print out:

Connecting to: mongodb+srv://username:myPassword@something.mongodb.net/test?retryWrites=true
list_databases():
{'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 = "cluster0-shard-00-00-jxeqq.mongodb.net"

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-
00-jxeqq.mongodb.net/test?retryWrites=true
Traceback (most recent call last):
  File "C:\Python36\lib\site-packages\pymongo\uri_parser.py", line 287, in _get_
dns_srv_hosts
    results = resolver.query('_mongodb._tcp.' + hostname, 'SRV')
  File "C:\Python36\lib\site-packages\dns\resolver.py", line 1102, in query
    lifetime)
  File "C:\Python36\lib\site-packages\dns\resolver.py", 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
rd-00-00-jxeqq.mongodb.net., _mongodb._tcp.cluster0-shard-00-00-jxeqq.mongodb.ne
t.rhinocorps.com.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "atlasConnect.py", line 35, in <module>
    client = pymongo.MongoClient(dbConn)
  File "C:\Python36\lib\site-packages\pymongo\mongo_client.py", line 494, in __i
nit__
    res = uri_parser.parse_uri(entity, port, warn=True)
  File "C:\Python36\lib\site-packages\pymongo\uri_parser.py", line 399, in parse
_uri
    nodes = _get_dns_srv_hosts(fqdn)
  File "C:\Python36\lib\site-packages\pymongo\uri_parser.py", line 289, in _get_
dns_srv_hosts
    raise ConfigurationError(str(exc))
pymongo.errors.ConfigurationError: None of DNS query names exist: _mongodb._tcp.
cluster0-shard-00-00-jxeqq.mongodb.net., _mongodb._tcp.cluster0-shard-00-00-jxeq
q.mongodb.net.<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.

Thanks,
Erik

It may be useful to know that:

ping cluster0-shard-00-00-jxeqq.mongodb.net

will return replies as expected.

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