开发者

Searching for records in pymongo using a datetime criteria

开发者 https://www.devze.com 2023-03-25 15:55 出处:网络
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)}

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/

0

精彩评论

暂无评论...
验证码 换一张
取 消