python 2.7 - mongodb query for date fields -
i save mongodb field 'date' datetime object , use following queries
1.db.test_collection.find({'date': {'$gte': start_date_time}}) 2. db.test_collection.find({"date": {"$gte": start_date_time, "$lte": end_date_time}
where start_date_time (say)2014-06-03 00:00:00 , end_date_time 2014-06-03 23:59:59 insert values mongodb, don't give results. please me solve issue.
you should use datetime
type.
import datetime db.test_collection.find({'date': {'$gte': datetime.datetime(2014, 6, 3, 16, 46) }})
you can see more in documentation (http://api.mongodb.org/python/current/tutorial.html)
hope works fine you!
Comments
Post a Comment