'mongodb date comparison between ISO string and datetime

I have a MongoDB collection where the date attribute is stored in the following format

{'date': "2014-05-28T13:02:46"}

I receive a query from the user in my Python server which is in the format '2014-05-28' that I have to compare against 'date'. I wrote the following query in Pymongo but it fails.

 signup_date = datetime.date(2014,5,28)
 signed_up_users = usercollection.find({'customer_id':'abc','date' :{"$gte":signup_date}})

I believe it's a date conversion issue.However, I can't modify the collection 'date' which is a string. So, I believe I have to parse it but can't find a way to parse it in PyMongo.



Solution 1:[1]

I was able to resolve this in the following way

signup_date_iso = datetime.date(2014,5,28).isoformat()

This converts into an ISO format date string that I can use to compare with the date strings stored in the database.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ubh