如何在pymongo中查询使用ISODATE?
长话短说,我正在尝试做 this 过去两天在Pymongo。请帮忙。
for x in restaurants.find(
{"grades":
{"$elemMatch":
{'date': dateutil.parser.parse("2014-08-11T00:00:00Z"),
'grade':'A',
'score':11
}}},
{"name":1,
"grades.grade":1,
"grades.score":1,
"grades.date":1
}):
print(x)
编辑:在这里's's the Database。它的结构:
我正在尝试编写一个查询,以查找餐厅ID,名称和成绩的成绩,这些餐厅的成绩达到了“ A”,并在iSodate上获得11分。” 2014-08-11T00: 00:00z“在许多调查日期中。
我开始认为我输入的日期或数据库有问题。另外,正如您在第四行代码中看到的,我正在使用时间对象。请尝试查询自己。它不起作用。
Long story short, I'm trying to do this query in PyMongo for the last two days. Please help.
for x in restaurants.find(
{"grades":
{"$elemMatch":
{'date': dateutil.parser.parse("2014-08-11T00:00:00Z"),
'grade':'A',
'score':11
}}},
{"name":1,
"grades.grade":1,
"grades.score":1,
"grades.date":1
}):
print(x)
Edit: Here's the database. It's Structure:
I'm trying to write a query to find the restaurant Id, name, and grades for those restaurants which achieved a grade of "A" and scored 11 on an ISODate "2014-08-11T00:00:00Z" among many of survey dates.
I'm starting to think there's something wrong with either the date I'm entering or the database. Also, as you can see in the fourth line of code I AM using a time object. Please try querying yourself. Its not working.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
pymongo
不使用“ iSodate”,它是mongo类型,您应该只使用datetime
创建一个时间对象,例如:pymongo
doesn't use "ISODate", it's a Mongo type, you should just usedatetime
to create a time object, like so: