We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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


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.


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();