Mr. Felix Mr. Felix - 1 month ago 8
PHP Question

MongoDB unwind commands

I'm trying to unwind an array inside a document.

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


Here is a working command:

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


I'm trying to use
db.runCommand
to do the same task:

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


But with this second options, I'm getting this error:


aggregation result exceeds maximum document size (16MB)


Aren't these commands the same? Why the second one is not working?

I'm using Mongo PHP Driver for PHP 7, that's why I'm aggregating in this way.

Answer

db.runCommand returns the result inside one document. So, all the aggregation result is larger than 16MB. Setting batchSize at cursor option might solve the problem.

Using MongoDB::execute, I can execute a query in this way: db.collection.aggregate(... just passing the original mongo syntax.