Adding another subdocument in a specific document without overwriting?


I am trying to add a subdocument to an array of documents. I have a collection with the following structure:

id name comments [ {name: fool, comment: fool}, {name: foolTwo, comment: foolTwo} ]

When I try to add another subdocument it replaces the existing one. In pure code I would like this:

$ collection-> update ( array ('_id' => new Mongoid ($ id)), array ('$ push' => array ("comments" => array ("name" => $ name, 'comment' => $ text,))));

How do I do this in the Phalcon?

Thank you for attention.


To update a subdocument:

  1. Create your model and call find/findFirst to populate it with data based on some condition (for example, _id)
  2. Add the new comment to the comments array.
  3. Save

it works! Thanx.