2016-11-10 4 views
2

現在、Python3(pymongo)を使用して、MongoプロトコルをサポートするAzureドキュメントDBに接続しています。mongodbプロトコルをサポートするazureドキュメントdbのコレクションを表示できません

# 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 dbで実行すると、期待どおりに動作します。

私はもともとデータベース内の既知のコレクションでクエリを実行しようとしていましたが、私はそれもできないようです。私はMongoChefを接続して、期待通りに働いています(querysを実行できる)。

私は間違っていますか?

+0

私の知る限りでは、ドキュメントDB上の現在のバージョンのmongoプロトコルはこれをサポートしていないので、空のリストを返すのです。 – 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}} 

希望します。

関連する問題