Python 我如何做大于/小于使用 MongoDB?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4791555/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I do greater than/less than using MongoDB?
提问by TIMEX
I'm using the pymongo driver.
我正在使用 pymongo 驱动程序。
Can someone take a look at pymongo and tell me how to do greater than? I"m used to doing : for everything.
有人可以看看 pymongo 并告诉我如何做大于吗?我习惯于:为了一切。
采纳答案by Xavier Barbosa
Have you seen the doc? Take from the manual :
你看过医生吗?从手册中获取:
>>> d = datetime.datetime(2009, 11, 12, 12)
>>> for post in posts.find({"date": {"$lt": d}}).sort("author"):
... post
...
{u'date': datetime.datetime(2009, 11, 10, 10, 45), u'text': u'and pretty easy too!', u'_id': ObjectId('...'), u'author': u'Eliot', u'title': u'MongoDB is fun'}
{u'date': datetime.datetime(2009, 11, 12, 11, 14), u'text': u'Another post!', u'_id': ObjectId('...'), u'author': u'Mike', u'tags': [u'bulk', u'insert']}
回答by trickwallett
gt& ltare the operators. See http://www.mongodb.org/display/DOCS/SQL+to+Mongo+Mapping+Chart
gt<是运算符。见http://www.mongodb.org/display/DOCS/SQL+to+Mongo+Mapping+Chart
回答by Sai Venkat
If you wanna query and find docs which have a field greater than something you can
如果您想查询和查找字段大于您所能找到的字段的文档
users.find({"age": {"$gt": 20}})
Check out the advanced query section of Mongodb for more reference.
查看 Mongodb 的高级查询部分以获取更多参考。
--Sai
--赛

