2

Working of OR operator in mongodb with php

$query = array(
        'table' => $table,
        'user_id' => array('$ne'=> null),
        '$or' => array('movies' => array('$ne' => null), 'comics' => array('$ne' => null) )
    );

$dbcollection->find($query);

Here I try to return whole records where movies array or comics array is not null, But I always return empty array. In database, movies or comics array is present in some records and some other records no movies or comics array is present.

How can I correct this query ?

8
  • @Micku: I using version 1.0.4 or 'OR' operator needs v1.6+, is it ? Commented May 30, 2012 at 5:47
  • "OR" operator is included only from version 1.7.x onwards. Commented May 30, 2012 at 5:48
  • When you say "1.0.4", do you mean the server version or the PHP Driver version? Try logging in with the mongo shell (type mongo) and it will tell you which version you are it. In any case, PHP driver version 1.0.4 is really old. And I don't think MongoDB version 1.0.4 exists. Don't you mean 2.0.4? Also, post a sample document with your question so we can have a look at what is stored. Commented May 30, 2012 at 10:15
  • @Derick: Can I get Mongo version from php code itself ? Commented May 30, 2012 at 11:39
  • 1
    @Derick: Thanks, The mongo version is 1.4.4. Commented May 30, 2012 at 15:15

1 Answer 1

2

The comments indicate that you are using MongoDB 1.4.4. The $or operator did not get introduced until MongoDB 1.6 as per documentation. MongoDB 1.4.4 is also really really old. Please upgrade!

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

1 Comment

Its my local server mongo version is 1.4.4, but in production server where the mongo version is 1.6.2 is also not working the OR operator. Any way Thanks for help...

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.