I have MongoDB collection with 50k+ documents like:
{
"_id" : ObjectId("5a42190e806c3210acd3fa82"),
"start_time" : ISODate("2017-12-25T02:29:00.000Z"),
"system" : "GL",
"region" : "NY",
"order_id" : 3,
"task_type" : "px2",
"status" : false
}
When I add a new order, Python script searches database for existing orders with the same start_time and task_type, like:
tasks_base.find_one({
"$and": [{
"start_time": plan_date.astimezone(pytz.UTC)
}, {
"task_type": px
}]
})
It works, but every new document in a collection slows it down (more documents to check, etc.).
As a solution, I want to add task_type
and start_time
as indexes for the collection. But have some concerns (date as index looks a bit unnatural). So, need an advice how to do it right (or additional ideas, how to speed up search). Grateful for any advice :)