Hello,
I have this document :
{
“_id”: “670cd1fafeb0a1ef44162a65”,
“post_id”: “9”,
“comments”: [
{
“_id”: “6717e0c7e074859fa50a75f3”,
“author_id”: “3”,
“comment_text”: “Hello”,
“replies”: [
{
“_id”: “67181338e074859fa50a7620”,
“author_id”: “9”,
“replies”: [ !!! INSERT THE ARRAY HERE !!! ]
}
]
}
]
}
I’m trying to insert this array WHERE “_id”: “67181338e074859fa50a7620” :
$array = array (
‘_id’ => new MongoDB\BSON\ObjectId(),
‘author_id’ => $_SESSION[‘userid’],
‘comment_text’ => ‘How are you’,
‘replies’ => array()
);
I Tried this but to no avail :
$updateResult = $db->updateOne(
[‘post_id’ => ‘9’, ‘comments.replies._id’ => new \MongoDB\BSON\ObjectID(‘67181338e074859fa50a7620’)], [‘$push’ => array(‘comments.replies.$.replies’ => $array)]
);
I tried also to use arrayFilters but I got it wrong too.
Thank you for your help,
Chuck