我有一个相当大的 mongo 聚合命令。
db.container_product.aggregate([
{"$unwind":"$product"},
{"$group":{"_id":"$product","container_ids":{"$push":"$container_id"}}}
])
它产生了近 5k 个组,但它们都是普通整数。例如:
{
"_id" : NumberInt(107058402),
"container_ids" : [
NumberInt(107058409),
NumberInt(107058410),
NumberInt(107058411),
NumberInt(107058412),
NumberInt(107058413)
]
}
当我在 shell(普通 shell,还有 Robomongo 等)中运行它时,它工作得很好。但是当我尝试从 PHP 运行它时,它给出了 16MB 的错误。
172.16.0.2:27017: exception: aggregation result exceeds maximum document size (16MB)
在这种情况下,PHP 和 shell 之间的巨大区别是什么?
如何解决这个问题?
最佳答案
Shell 使用 js 包装器来处理 aggregate command ,它隐式使用 cursor ,因此它可以返回任何大小的结果(每个文档 16 MB 的限制仍然适用)。您可以通过调用 db.collection.aggregate
查看包装器的源代码在外壳中。
在 PHP 中 MongoCollection::aggregate直接调用该命令以返回单个文档,而不是光标。您需要使用MongoCollection::aggregateCursor相反。
关于php - 为什么 mongo 聚合在 shell 中可以工作,但在 PHP 中却超过 16MB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45233625/