Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法列出具有mongodb协议支持的azure document db中的集合_Python_Mongodb_Azure_Azure Cosmosdb - Fatal编程技术网

Python 无法列出具有mongodb协议支持的azure document db中的集合

Python 无法列出具有mongodb协议支持的azure document db中的集合,python,mongodb,azure,azure-cosmosdb,Python,Mongodb,Azure,Azure Cosmosdb,我目前正在使用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.mong

我目前正在使用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())
#对连接字符串的引用
self.connection_string=“mongodb://:@://?ssl=true”
#创建连接(正在工作)
self.mongo\u client=MongoClient(self.connection\u字符串)
#显示数据库和集合
打印(self.mongo\u client.database\u names())
对于self.mongo\u client.database\u names()中的db\u name:
打印(db\u name,“>”,self.mongo\u客户端[db\u name].collection\u names())
运行上述代码片段会列出数据库,但不会列出集合。在本地mongo db上运行此功能可以正常工作

我最初试图在数据库中的已知集合上运行查询,但是,我似乎无法做到这一点。我已连接MongoChef并按预期工作(能够运行查询)


你知道我做错了什么吗?

@green,这个问题似乎是由
pymongo
引起的,而不是
DocumentDB和MongoDB协议引起的

我尝试使用第三方工具
Robomongo
成功地将
DocumentDB与MongoDB协议连接起来,我可以看到如下集合

作为参考,这里是一种通过数据库级命令在PyMongo中列出集合的变通方法,请参见下文

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

希望有帮助。

据我所知,文档数据库上的mongo协议的当前版本似乎不支持此功能,这就是它返回空列表的原因。