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 $in in ODM (Mongo)

Hi,

I am trying to use $In operator in ODM find(); Below is my code but does not work. Anyone know what is the syntax?

$products = Products::find(array(
        array(
            '$in' => array('tags' => array('beauty')),
            '$or' => array(
                        array('endDateTime' => ''),
                        array('endDateTime' => array('$gt' => new Mongodate(strtotime("now"))))
            )               
        ),
        "sort"  => array("_id" => -1)
    ));


27.8k
Accepted
answer
edited Jul '15

Got the right syntax. Here's the code for the benefit of others.

$products = Products::find(array(
    array(
        'tags' => array('$in' => array('beauty')),
        '$or' => array(
                    array('endDateTime' => ''),
                    array('endDateTime' => array('$gt' => new Mongodate(strtotime("now"))))
        )               
    ),
    "sort"  => array("_id" => -1)
));