need to query MongoDB using php

Posted by Mario Villarroel on Stack Overflow See other posts from Stack Overflow or by Mario Villarroel
Published on 2012-08-29T15:20:58Z Indexed on 2012/08/29 21:38 UTC
Read the original article Hit count: 230

Filed under:
|

I need to query mongodb with something like this:

("something" < X OR "something" = "nll") AND ("someother">X OR "someother"= "nll") AND z=$z AND s=1

I've tried a few things, but can't get it to work, this is what I've tried:

find( array( '$or'=>array(array("something"=>array("$le",$X)),array("something"=>"nll")), '$or'=>array(array("someother"=>array("$ge",$X)),array("someother"=>"nll")) ))

But that's getting me the OR overwritten, so I'm lost on that...

After diggin a bit more, I assembled this code that seems to be what I need, but doesn't work either:

find( array('$and'=>array( array( '$or' => array( array("something"=>array('$gte'=>$X)),array("something"=>"nll"))), array('$or' => array( array("someother"=>array('$lte'=>$X)),array("someother"=>"nll")))),"Z"=>$z, "s"=>"1");

But this doesn't work as it returns zero results and I know for sure that there are more than 2 items that match on the db. (100% certain)

© Stack Overflow or respective owner

Related posts about mongodb

Related posts about mongodb-php