0

I need to get data from Mongodb Database, My code as follow,

    $collection = $global["dbmongo"] -> person_uuid;
    $rows = $collection->find(array("p_uuid" => $global['uuid'],
            '$or'=>array(

                    'expiry_date'=>null,
                    'expiry_date'=> '0000-01-01 00:00:00'
            )
    )
    );

But it shows,

$or requires nonempty array

if i write echo "count".$count; var_dump($rows); Then the output is countArrayobject(MongoCursor)#48 (0) { }, addition to above output Please help me.

5
  • array !== associative array / map Commented Dec 1, 2013 at 14:38
  • $or is an array of arrays, with each element of the parent array being a clause Commented Dec 1, 2013 at 14:38
  • @Prinzhorn It does in PHP Commented Dec 1, 2013 at 14:38
  • Thanks, So how can i fix that ? In test case, I finding with 'expiry_date'=> '0000-01-01 00:00:00' Commented Dec 1, 2013 at 14:42
  • wrap each line of the $or clause with array( so it is an set of array clauses Commented Dec 1, 2013 at 14:51

1 Answer 1

2

The problem is with this part:

array(
  'expiry_date'=>null,
  'expiry_date'=> '0000-01-01 00:00:00'
)

The keys are the same and because of this one overwrites another. You can use $in operator and do something like

'expiry_date' => array(
  '$in' => array(null, '0000-01-01 00:00:00')
)

Also it is hard to understand what exactly are you looking for here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.