我想计算一段时间后存储在MongoDB中的对象数。日期以以下格式存储在MongoDB中
"clickTime" : ISODate("2016-07-09T07:17:29.932Z")
我编写了下面的代码来计算对象,但是它给了我_count = 0
,而它应该给我_count = 1
。我在Django做这个
def Count(request):
time_from = datetime.time(0, 0, 0)
## today's count
d1 = datetime.date.today()
start1 = datetime.datetime.combine(d1,time_from)
end1 = datetime.datetime.now()
count1 = utils.Processor1(collect,start1,end1)
这是我的实用程序文件
def Processor1(collect,start,end):
_count = collect.find({"clickTime":{"$gte":start,"$lte":end}}).count()
return _count
根据您的问题,我不太确定您的
start
和end
变量是什么类型的,但请在将它们设置为datetime
实例时尝试如下:相关问题 更多 >
编程相关推荐