为什么mongo聚合在shell中工作但在PHP中超过16MB

Kon*_*nia 2 php mongodb mongo-shell

我有一个非常庞大的mongo聚合命令.

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

它产生了近5k组,但它们都是普通的整数.例如:

{ 
    "_id" : NumberInt(107058402), 
    "container_ids" : [
        NumberInt(107058409), 
        NumberInt(107058410), 
        NumberInt(107058411), 
        NumberInt(107058412), 
        NumberInt(107058413)
    ]
}
Run Code Online (Sandbox Code Playgroud)

当我在shell(普通shell,还有Robomongo等)中运行它时它工作得很好.但是当我尝试从PHP运行它时,它给了我16MB的错误.

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

在这种情况下,PHP和shell之间的巨大差异是什么?

我怎么解决这个问题?

Ale*_*lex 5

Shell使用js包装器作为aggregate命令,它隐式使用游标,因此它可以返回任何大小的结果(每个文档的限制仍然适用16 MB).您可以通过调用db.collection.aggregateshell 来查看包装器的源代码.

在PHP中,MongoCollection :: aggregate直接调用命令返回单个文档,而不是游标.您需要使用MongoCollection :: aggregateCursor.