I need to perform a query based on the value of some boolean fields. These fields may not exist in some documents, as they were added at a later stage.
I tested the query in the shell and worked ok:
db.product.find({$or: [{approved:true},{$and: [{approved:{$exists:false}}, {sold:{$ne:true}}]}]})
But trying to do the same with the PHP driver doesn't seem to work:
$condA = array('approved' => true);
$condB = array('approved' => array('$exists' => false), 'sold' => array('$ne' => true));
$query = array('pid' => $prodId, '$or' => array($condA, array('$and' => $condB)));
I tested some variants but I'm always getting this error in the log:
assertion 13086 $and/$or/$nor must be a nonempty array
Any hint on what I might be doing wrong? Thanks in advance.