首页 > 解决方案 > Efficient Retrieve of MongoDB items in a time range

问题描述

I am having a MongoDb collection of 70M items (200GB) and I am trying to get those in the range [from_date, to_date] using the command:

from_date = datetime.datetime(2015, 1, 14, 9, 46, 23)
to_date = datetime.datetime(2015, 1, 14, 9, 46, 24)
db.collection.find({"datetime": {"$gte": from_date, "$lte": to_date}})

However it takes a lot of time to retrieve those items even for a single query. Is there any more efficient way to do this?

标签: mongodb

解决方案


推荐阅读