无法在具有 mongodb 协议支持的 azure 文档数据库中列出集合
unable to list collections in azure document db with mongodb protocol support
我目前正在使用 Python3 (pymongo) 连接到具有 Mongo 协议支持的 Azure 文档数据库。
# 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 并按预期工作(能够 运行 查询)。
知道我哪里做错了吗?
@Greener,问题似乎是由pymongo
引起的,而不是DocumentDB with MongoDB protocol
。
我尝试使用第三方工具 Robomongo
连接 DocumentDB with MongoDB protocol
成功,我可以看到如下集合。
作为参考,这是一种通过数据库级命令 listCollections
在 PyMongo 中列出集合的变通方法,请参见下文。
>>> mongo_client.command('listCollections')
{'ok': 1, '_t': 'ListCollectionsResponse', 'cursor': {'firstBatch': [{'options': {}, 'name': 'testCollection'}], 'ns': 'testdb.$cmd.listCollections', 'id': 0}}
希望对您有所帮助。
我目前正在使用 Python3 (pymongo) 连接到具有 Mongo 协议支持的 Azure 文档数据库。
# 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 并按预期工作(能够 运行 查询)。
知道我哪里做错了吗?
@Greener,问题似乎是由pymongo
引起的,而不是DocumentDB with MongoDB protocol
。
我尝试使用第三方工具 Robomongo
连接 DocumentDB with MongoDB protocol
成功,我可以看到如下集合。
作为参考,这是一种通过数据库级命令 listCollections
在 PyMongo 中列出集合的变通方法,请参见下文。
>>> mongo_client.command('listCollections')
{'ok': 1, '_t': 'ListCollectionsResponse', 'cursor': {'firstBatch': [{'options': {}, 'name': 'testCollection'}], 'ns': 'testdb.$cmd.listCollections', 'id': 0}}
希望对您有所帮助。