Answer the question
In order to leave comments, you need to log in
How to update an object in an array in a mongodb collection (php)?
I have an object in the collection:
{
_id:{},
name: 'name',
someArray: [{
id: 234,
info: 'some info'
}, {
id: 567,
info: 'other info'
}]
}
Answer the question
In order to leave comments, you need to log in
Lots of options. For example, updating with a search query:
$retval = $col->findAndModify(
["name" => "name"],
['$set' => ['someArray.0.info' => 'update info']],
);
$doc = $col->find(["name" => "name"]);
$doc['someArray'][0]['info'] = 'update info';
$col->save($doc);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question