Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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


14.0k
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)
));