MongoDB展开命令

时间:2016-10-17 16:02:54

标签: php mongodb

我正在尝试在文档中展开数组。

{ //document
    ...
    parameters : [{...}, {...}, ...]
}

这是一个有效的命令:

db.getCollection('inventory').aggregate([
    { $unwind : "$parameters" }
]);

我正在尝试使用db.runCommand执行相同的任务:

db.runCommand({
    aggregate: "inventory",
    pipeline: [{ $unwind: "$parameters" }]
});

但是有了第二个选项,我收到了这个错误:

  

聚合结果超出最大文档大小(16MB)

这些命令不一样吗?为什么第二个不起作用?

我正在使用Mongo PHP Driver for PHP 7,这就是我以这种方式聚合的原因。

1 个答案:

答案 0 :(得分:0)

db.runCommand将结果返回到一个文档中。因此,所有聚合结果都大于16MB。在batchSize选项设置cursor可能会解决问题。

使用MongoDB::execute,我可以用这种方式执行查询:db.collection.aggregate(...只传递原始的mongo语法。