mongo aggregate result exceed maximum document size

被刻印的时光 ゝ 提交于 2020-05-25 11:36:07

问题


I use mongo aggregate function to find duplicated documents in a collection, where the collections looks like the following:

{_id, placement_id, placement_name, program_id, target}

I need to find all the documents that have exactly the same fields except _id and placement_id, so this two documents are the same:

{_id:3, placement_id:23, placement_name:"pl1", program_id:5, target:"-"}
{_id:7, placement_id:55, placement_name:"pl1", program_id:5, target:"-"}

The aggregate function I came up with is:

db.placements.aggregate({$group:{_id:{placement_name:"$placement_name", program_id:"$program_id", target:"$target"}, total:{$sum:1}}},{$match:{total:{$gte:2}}});

Then mongo just returned:

Error: Printing Stack Trace
    at printStackTrace (src/mongo/shell/utils.js:37:15)
    at DBCollection.aggregate (src/mongo/shell/collection.js:897:9)
    at (shell):1:15
Wed Apr  2 07:43:23.090 aggregate failed: {
    "errmsg" : "exception: aggregation result exceeds maximum document size (16MB)",
    "code" : 16389,
    "ok" : 0
} at src/mongo/shell/collection.js:898

the aggregate is correct, I tested it on a smaller collection and it works fine, but the production collection has about 80M documents. I was wondering when trying the find() function on 80M documents, it works and asking you to type 'it' for more records. How come the aggregate function doesn't have this capability? I also tried to append limit() to the end of the aggregate function but it won't work either. Any work around? Thanks.


回答1:


how come aggregate function don't have this capability?

It does in 2.6 which will be out very soon.

i also tried to append limit() to the end of the aggregate function, it won't work either. any work around?

There is a $limit operator for the aggregation framework: http://docs.mongodb.org/manual/reference/operator/aggregation/limit/




回答2:


I was running into the same issue there. After googling I found out that you can use the runCommand in Mongo to use the aggregation and set the allowDiskUse option to true, to use the hard drive as an extension of the memory. enter link description here



来源:https://stackoverflow.com/questions/22816083/mongo-aggregate-result-exceed-maximum-document-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!