I am trying to get documents by date range and then aggregate on those documents. Right now, I am trying the following to achieve that.
import datetime,time
import pymongo
from bson.son import SON
con1 = pymongo.MongoClient("myHost",27017)
db = con.myDB
posix_time1 = time.mktime(datetime.datetime(2015, 07, 14, 0, 0, 0).timetuple())
posix_time2 = time.mktime(datetime.datetime(2015, 07, 15, 0, 0, 0).timetuple())
pipeline = [
{"$match":{"time":{"$gte":int(posix_time1),"$lt":int(posix_time2)}}},
{"$unwind":"$foo1"},
{"$group":{"_id":"$foo1.boo","sum1":{"$sum":"$foo1.boo1"}}},
{"$sort":SON([("sum1",-1)])}
]
print(list(db.myColl.aggregate(pipeline)))
But, the result is an empty list. My guess is the problem with the dates I am passing. Please point me towards better solution.
Thank You!