Setup, php + mongodb.
The database should contain multiple items where ‘Title’ contains both ‘Apple’ and ‘Orange’. I am trying to obtain only the items that contain BOTH ‘Apple’ and ‘Orange’.
$regexOne = new MongoRegex( '/Apple/i' );
$regexTwo = new MongoRegex('/Orange/i');
$cursor = $collection->find( array( '$and' => array( array('Title' => $regexOne), array('Title' => $regexTwo) ) ) );
The same query with the ‘$and’ replaced with a ‘$or’ works correctly (or at least appears to), but this returns nothing despite there being data in the database that matches these conditions.
Echoing what dimo414 said, the first step is simply comparing Mongo’s shell to PHP. Both of these are equivalent:
And in PHP (using phpsh):