MongoDB equivalent of SQL “OR”

99封情书 提交于 2019-12-09 13:44:14

问题


So, MongoDB defaults to "AND" when finding records. For example:

db.users.find({age: {'$gte': 30}, {'$lte': 40}});

The above query finds users >= 30 AND <= 40 years old.

How would I find users <= 30 OR >= 40 years old?


回答1:


There will be an or operator in the near future. The nightly Mongodb build has already an $or. You can also use $where and use JavaScript to express the or.

See http://groups.google.com/group/mongodb-user/browse_thread/thread/a9a4d8b863d84601




回答2:


There is no OR operator, but they say you can still do it:

http://www.mongodb.org/display/DOCS/OR+operations+in+query+expressions




回答3:


matt -i too researched the $or business and hit a brick wall. i had saved this little link on googlegroups and was going to follow up on it at some point:

http://groups.google.com/group/mongodb-user/browse_thread/thread/4ac6f67622b3b951

sorry to not have answered the question but just wanted to make you aware that others were looking for the same functionailty at the time i was tentatively looking at this.

you could of course (depending on the language implementation) use the linq provider for mongo.

jim

[edit] for linq stuff see - http://schotime.net/blog/index.php/2010/04/29/nosql-norm-mongodb-and-regular-expressions/



来源:https://stackoverflow.com/questions/3038114/mongodb-equivalent-of-sql-or

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!