I am currently using Python3 (pymongo) to connect to an Azure Document DB with Mongo protocol support.
# reference to connection string
self.connection_string = "mongodb://<user>:<pw>@<location>:<port>/<database>?ssl=true"
# creates the connection (this is working)
self.mongo_client = MongoClient( self.connection_string )
# show databases and there collections
print(self.mongo_client.database_names())
for db_name in self.mongo_client.database_names():
print(db_name,">",self.mongo_client[db_name].collection_names())
Running the above snippet of code lists the databases however the collections are not listed. Running this on a local mongo db works as expected.
I was originally trying to run a query on a known collection within the database however, I can't even seem to be able to do that. I have MongoChef connected and is working as expected (able to run querys).
Any ideas what I could be doing wrong?
@Greener, the issue seems to be caused by pymongo, not DocumentDB with MongoDB protocol.
I tried to connect DocumentDB with MongoDB protocol using the third party tool Robomongo successfully, and I could see the collections as below.

As reference, here is a workaround way for listing collections in PyMongo via Database level command listCollections, please see below.
>>> mongo_client.command('listCollections')
{'ok': 1, '_t': 'ListCollectionsResponse', 'cursor': {'firstBatch': [{'options': {}, 'name': 'testCollection'}], 'ns': 'testdb.$cmd.listCollections', 'id': 0}}
Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With