Search code examples
phpmongodbfat-free-framework

Or filter in F3


To filter my documents in MongoDB I use this: $filter = array('title' => $regex ? $regex : new \MongoRegex('/.*/i'));

I am also using the Pagination plugin if that matters.

I need to be able to filter to the title or description. Something like this: $filter = array('title' => $regex ? $regex : new \MongoRegex('/.*/i') OR 'description' => $regex ? $regex : new \MongoRegex('/.*/i'));

Any help on this would be much appreciated :D


Solution

  • I think it's something like that (but untested):

    array(
     "$or"=> [
       "title": $regex ? $regex : new \MongoRegex('/.*/i'),
       "description": $regex ? $regex : new \MongoRegex('/.*/i')
     ]
    )