【发布时间】:2015-02-01 01:46:13
【问题描述】:
我在使用 pymongo 进行 mongodb 聚合时遇到了aggregation result exceeds maximum document size (16MB) 错误。
我一开始可以使用limit() 选项克服它。然而,在某些时候我得到了
Exceeded memory limit for $group, but didn't allow external sort. Pass allowDiskUse:true to opt in." error.
好的,我将使用{'allowDiskUse':True} 选项。此选项在我在命令行上使用时有效,但当我尝试在我的 python 代码中使用时
result = work1.aggregate(pipe, 'allowDiskUse:true')
我收到TypeError: aggregate() takes exactly 2 arguments (3 given) 错误。 (尽管http://api.mongodb.org/python/current/api/pymongo/collection.html#pymongo.collection.Collection.aggregate:aggregate(pipeline, **kwargs) 给出了定义)。
我尝试使用 runCommand,或者说它是 pymongo 等价物:
db.command('aggregate','work1',pipe, {'allowDiskUse':True})
但现在我又回到了“聚合结果超出最大文档大小 (16MB)”错误
如果你需要知道
pipe = [{'$project': {'_id': 0, 'summary.trigrams': 1}}, {'$unwind': '$summary'}, {'$unwind': '$summary.trigrams'}, {'$group': {'count': {'$sum': 1}, '_id': '$summary.trigrams'}}, {'$sort': {'count': -1}}, {'$limit': 10000}]
谢谢
【问题讨论】:
标签: mongodb aggregation-framework pymongo