How to update object in an array in a mongodb collection (php)?

Have the object in the collection:
{
_id:{},
 name: 'name',
 someArray: [{
 id: 234,
 info: 'some info'
 }, {
 id: 567,
 info: the 'other info'
}]
}

For example, I need to change in object with id 567 info, how can this best be done? Object in the array to find work, but the flash of life - no. In Kutch-ve language use puff. Thank you!
July 2nd 19 at 17:35
2 answers
July 2nd 19 at 17:37
code show, and then all of Vanga on vacation
If I had code, I would not be writing here;) I just need an example of the update array. For example, to add an item, you need to use something like
$db->updateOne(
[],
['userData'=>['$addToSet'=>(object)['id'=> '12345']]]
)
Or I need to update the item or delete it. The option with the $pull decreases with accessenum that is not an array - arianna.Morisset commented on July 2nd 19 at 17:40
:
>> bject in the mountains to find work, but the flash of life - no
of course not, if there is no code. - albertha.Medhur commented on July 2nd 19 at 17:43
July 2nd 19 at 17:39
A lot of options. For example, the update query with search:
$retval = $col->findAndModify(
 ["name" => "name"],
 ['$set' => ['someArray.0.info' => 'update info']],
);

Or if processing is significant:
$doc = $col->find(["name" => "name"]);
$doc['someArray'][0]['info'] = 'update info';
$col->save($doc);

Find more questions by tags MongoDBPHP