I want to limit a query I\'m making to only look in documents that were created in the past 24 hrs.
What is the best way to structure this query? How do I go about
Hope this helps someone. I'm using pymongo to query last 24 hours of data. In my case I had to convert the current time into BSON timestamp.
First I had to import Bson timestamp:
from bson.timestamp import Timestamp
Then in my search query I did the following:
yesterday = datetime.datetime.now() - datetime.timedelta(days=1)
findQuery = {
"unix": {
"$gte": Timestamp(int(yesterday.strftime("%s")),0)
}
}