2016-11-10 42 views
2

我目前使用Python3(pymongo)連接到具有Mongo協議支持的Azure文檔數據庫。無法列出azure文檔數據庫中的集合,並支持mongodb協議

# 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()) 

運行上面的代碼片段中列出但集合中未列出的數據庫。在本地mongo數據庫上運行這個按預期工作。

我最初試圖在數據庫中的已知集合上運行查詢,但是我似乎無法做到這一點。我有MongoChef連接並按預期工作(能夠運行查詢)。

任何想法我可能做錯了什麼?

+0

據我所知,這看起來對文件分貝蒙戈協議的當前版本不支持這一點,這就是爲什麼它返回一個空列表。 – Greener

回答

3

@Greener,這個問題似乎是由pymongo造成的,而不是DocumentDB with MongoDB protocol

我試圖成功地使用第三方工具Robomongo連接DocumentDB with MongoDB protocol,我可以看到如下集合。

enter image description here

作爲參考,這裏是通過數據庫級​​命令listCollections在PyMongo上市藏品解決方法的方式,請參見下文。

>>> mongo_client.command('listCollections') 
{'ok': 1, '_t': 'ListCollectionsResponse', 'cursor': {'firstBatch': [{'options': {}, 'name': 'testCollection'}], 'ns': 'testdb.$cmd.listCollections', 'id': 0}} 

希望它能幫助。

相關問題