Patrickkx
Patrickkx

Reputation: 1870

Mongodb find - or operator?

I have little bit complicated situation -

User.find({ isNew: true, isYellow: true, isBlue: true })
           ^^^required            ^^^^^^^^^^^ one of them must be TRUE

as you can see above, isYellow or isBlue must be true. I can't use $or here, because its about two keys, not two values in one key.

Question: How to make query find all users with isNew === true and isYellow OR isBlue true?

Thank you!

Upvotes: 2

Views: 52

Answers (1)

JohnnyHK
JohnnyHK

Reputation: 311835

$or works with query expressions, not values, so it works fine for your case:

User.find({ isNew: true, $or: [{isYellow: true}, {isBlue: true}] })

Upvotes: 2

Related Questions