如何使用 Cosmos API 消除 MongoDB 聚合查询的 40MB 查询限制

How to eliminate the 40MB query limit of MongoDB aggregate queries with Cosmos API

我在数据库中有两个集合,分别称为工作表、资产负债表和收入,需要在名为“_id”的字段中加入它们

我正在尝试对两个中等大的集合执行聚合,我将限制设置为 1,以便只得到一个结果。

但是,当我确定一个结果不会达到 40MB 时,我仍然达到 40MB 的限制

uri = "connection string"
client = pymongo.MongoClient(uri)
db = client.sheets
pipeline = [{'$lookup': 
                {'from' : 'balancesheet',
                 'localField' : '_id',
                 'foreignField' : '_id',
                 'as' : 'company'}},
            {'$limit': 1},

             ]

for doc in (db.income.aggregate(pipeline)):
    pprint (doc)

运行 下面的代码会解决这个错误:

"OperationFailure: Query exceeded the maximum allowed memory usage of 40 MB. Please consider adding more filters to reduce the query response size."

有没有办法用limit来解决这个问题?

感谢您的反馈。还有其他用户也面临类似的问题。 此问题已上报给产品组,他们正在积极致力于改进 agg。 fwk 和 post-GA 将取消此限制。

与此同时,您可以使用以下解决方法: 1)减少每个文档使用的字段 2) 减少查询覆盖的文档总数。

参考 GitHub 话题:https://github.com/MicrosoftDocs/azure-docs/issues/16997/

如果您仍有疑虑,请告诉我们。