开发者

MongoDB: OR operator

This query results in 3 objects:

db.list.find({ "Visibility": 4 })

This is expected. Now, when I run this query my result is 0 objects:

db.list.find({ "$or" : [ { "Visibility": 4 } ] } )

I would expect the same result in both cases since, in my understanding, a OR would be true if any one of开发者_StackOverflow中文版 the conditions are true.

So.. Am I missing something obvious here?


I've done the same test as @AdaTheDev in 1.6.5 mongo version and got expected results. So i suppose that you using mongodb version before 1.5.3 that does not support $or at all.

The $or operator lets you use a boolean or expression to do queries. You give $or a list of expressions, any of which can satisfy the query.
New in MongoDB 1.5.3


That looks find to me - a quick test here shows that does work.

Here's the whole test I ran:

db.Test.insert({_id: 1, Visibility: 1})
db.Test.insert({_id: 2, Visibility: 4})
db.Test.insert({_id: 3, Visibility: 3})
db.Test.insert({_id: 4, Visibility: 4})
db.Test.find({$or : [{Visibility: 4}]})

Sure enough, it returns _ids 2 and 4 as expected. I'm using 1.8.0, which version are you using?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜