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 use $inc in ODM

How do i use $inc using the object document mapper.

db.products.update(
   { sku: "abc123" },
   { $inc: { quantity: -2, "metrics.orders": 1 } }
)
edited May '16

Have you tried with something like

db.products.update(
   [ sku => "abc123" ],
   [ "$inc" => [ quantity => -2, "metrics.orders" => 1 ] ]
)

or using array() instead of [] if using older PHP?



27.7k

hmm, i am using the object document mapper. when i use ::update it says, function cannot be found



27.7k

In the end i stick to the below. Any difference from using $inc? performance wise?

public function _incrementPageviews($id){
    $page = Page::findById( $id );
    $page->pageViews += 1;
    $page->save();
}