Why mongo aggregate works in the shell but exceeds 16MB in PHP

Viewed 210

I'm having a quite huge mongo aggregate command.

db.container_product.aggregate([
    {"$unwind":"$product"},
    {"$group":{"_id":"$product","container_ids":{"$push":"$container_id"}}}
])

It results in almost 5k groups, but they're all plain integers. For example:

{ 
    "_id" : NumberInt(107058402), 
    "container_ids" : [
        NumberInt(107058409), 
        NumberInt(107058410), 
        NumberInt(107058411), 
        NumberInt(107058412), 
        NumberInt(107058413)
    ]
}

And it works just fine when I run it in the shell (plain shell, but also Robomongo etc.). But when I try to run it from the PHP it gives me 16MB error.

172.16.0.2:27017: exception: aggregation result exceeds maximum document size (16MB)

What's the huge difference between PHP and shell in this case?

How can I solve this problem?

1 Answers
Related