How to '$push' data into array while updating MongoDB in ODM?

Hello,

how to perform '$push' operation in ODM? In native MongoDB driver this operation supported in update method. How to use this operator in Phalcon\Mvc\Collection::save() and it's possible?

Did you ever find an answer to this? Or can anyone answer it? I'm also unsure of how this is done.



3.0k

Here is how I do it:

// get an object in your prefered way $odm = YourOdm::findFirst();

// treat the field like the PHP array it is $odm->someArray['newKey'] = 'newVal';

// or $odm->someOtherArray[] = 'newVal';

// then save $odm->save();