Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

MongoDB/Phalcon How to set OR condition

Hello, I need some help to solve a ODM issue. I try to make an or condition.

In mongo shell, it is:

db.reference_forums.find( { $or: [ { language: 'fr' }, { code: 'mycodehere' } ] } )

The query works fine

In App, My code is:

$forumlist = Forums::find(array(
                '$or' => array(
                    array( 'code' => 'mycodehere'),array( 'language' => 'fr')
                )
));

This query doesn't work : it returns all element without filter on the condition.

I hope someone else using OR condition query on Phalcon

Many thanks



82.7k
Accepted
answer

Try:

$forumlist = Forums::find(array(
    array(
        '$or' => array(
            array('code' => 'mycodehere'),
            array('language' => 'fr')
        )
    )
));


1.6k

It works fine, Many thanks

edited Apr '16

Hello MEHEUT.. I know that your problem was solved.. I am not familiar with MongoDB but one of my friend suggest me a good resource for better understanding of MongoDB i would like to share with you.