This is my Object on mongoDB, I need to find the relations objects in the array by ID and remove it object.
{
"_id" : ObjectId("5b1a95c84700cb01758b4568"),
"name" : "development",
"type" : "",
"relations" : [
{
"_id" : ObjectId("5b1c290f20244eec02000029"),
"name" : "mobile",
"count" : 0
},
{
"_id" : ObjectId("5b1c290f20244eec02000028"),
"name" : "iOS",
"count" : 0
}
]
}
What is the best way to find by relations object "_id" and then unset this object?
Here I am so getting ID
$cursor = $collection->find([], ['relations' => []]);
$find_id = "5b1c290f20244eec02000028";
foreach (iterator_to_array($cursor) as $key) {
foreach ($key['relations'] as $key2) {
if ((string)$key2['_id'] == $find_id) {
var_dump($key2['_id']);
}
}
}