Skip to content

Instantly share code, notes, and snippets.

@devrim
Created October 15, 2010 18:50
Show Gist options
  • Save devrim/628727 to your computer and use it in GitHub Desktop.
Save devrim/628727 to your computer and use it in GitHub Desktop.
Mongo $exists problem
$q = array("myKey" => array('$exists'=>true));
$cursor = $mongo->db->coll->find($q);
echo $cursor->count(); // this returns the number 51
while($cursor->hasNext()){
$v = $cursor->getNext();
print_r($v); // this returns nothing
}
@devrim
Copy link
Author

devrim commented Oct 15, 2010

solved it - if you do

$q = array("myKey.Subkey" => array('$exists'=>true));

then it works. i guess it's a weird bug on php driver.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment