【问题标题】:unable to list collections in azure document db with mongodb protocol support无法在具有 mongodb 协议支持的 azure document db 中列出集合
【发布时间】:2016-11-10 10:39:14
【问题描述】:

我目前正在使用 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())

运行上面的 sn-p 代码会列出数据库,但不会列出集合。在本地 mongo db 上运行它可以按预期工作。

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

有什么想法我可能做错了吗?

【问题讨论】:

  • 据我所知,当前版本的文档 db 上的 mongo 协议似乎不支持这一点,这就是它返回空列表的原因。

标签: python mongodb azure azure-cosmosdb


【解决方案1】:

@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}}

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 2017-05-23
    • 1970-01-01
    • 1970-01-01
    • 2017-05-14
    • 2016-11-20
    • 2013-02-18
    • 2017-09-21
    • 2017-04-21
    • 1970-01-01
    相关资源
    最近更新 更多