We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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



98.9k
Accepted
answer

Try:

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


4.2k

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.