I have a document in MongoDB and I\'m trying to unwind it in PHP. I want to unwind a document that has a subdocument that contains yet anothersubdocument. I was able to do t
I know that what you're trying to do is possible with MongoDB. The aggregate()
command can take as many arguments as you need.
In the mongo shell, a command like this
db.collection.aggregate(
{ $project: {
_id: 1,
items: 1
} },
{ $unwind: '$items' },
{ $unwind: '$items.images' }
);
will unwind the items
subdocument, then the images
subdocument.
Based on the code in your question, perhaps this will work
$project = array(
'$project' => array(
'_id' => 1,
'items' => 1,
)
);
$unwind_items = array(
'$unwind' => '$items'
);
$unwind_images = array(
'$unwind' => '$items.images'
);
$query = $mongo->store->aggregate($project,$unwind_items,$unwind_images);