Searching for records in pymongo using a datetime criteria
In pymongo, the command mycoll.find_one()
returned the following:
{u'name': u'John',u'sex':u'male',u'id':u'xbc541d',u'signup_date': datetime.datetime(2010, 12, 18, 22, 49, 20, 22000)}
If i search for a record using signup_date,no record shows up. That is mycoll.find({'signup_date':datetime.datetime(2010, 12, 18, 22, 49, 20, 22000)})
does not return any records.
What is the error in my syntax for finding records using the date ?
Please He开发者_高级运维lp Thanks
I just did a same search on my database and it worked. Try giving the following:
mycoll.find({'signup_date':datetime(2010, 12, 18, 22, 49, 20, 22000)})
You can also try option of narrowing your search results with "$gt" and "$lt" queries.
http://cookbook.mongodb.org/patterns/date_range/
精彩评论