Jisson
Jisson

Reputation: 3725

mongodb query for date fields

I save a mongodb field 'date' as datetime object and 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 is (say)2014-06-03 00:00:00 and end_date_time 2014-06-03 23:59:59 i insert some values to mongodb, But I don't give any results. please help me to solve the issue.

Upvotes: 0

Views: 216

Answers (1)

fmgonzalez
fmgonzalez

Reputation: 823

You should use the datetime type.

import datetime

db.test_collection.find({'date': {'$gte': datetime.datetime(2014, 6, 3, 16, 46) }})

You can see more in the documentation (http://api.mongodb.org/python/current/tutorial.html)

Hope it works fine for you!

Upvotes: 1

Related Questions