V
V
Vas3K2010-11-23 08:29:13
MongoDB
Vas3K, 2010-11-23 08:29:13

How to OR in MongoDB?

To select fields by conjunction of two conditions, we simply write:
db.blabla.find({ field1: value1, field2: value2 })

but how to make the query be with disjunction? To select everything, where field1 = value1 OR field2 = value2?

Maybe I'm very bad at reading mana, but I've been fighting for a long time, usually I found a way to get around (sometimes through $in, if the field is one), but now I'm at an impasse.

upd: While I was publishing the post, I found that the $or feature was added in 1.5.3. That is, in 1.4 there is no way? How did you live before?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
pwlnw, 2010-11-23
@pwlnw

And since when did the use of nosql become convenient?
Be patient. Write two requests.

C
casey, 2010-11-24
@casey

There is no way in 1.4. Basta :-) You can do (but very slowly) or, specifying the code where you can do anything as one of the find js criteria.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question