我有 50k+ 文档的 MongoDB 集合,例如:
{
"_id" : ObjectId("5a42190e806c3210acd3fa82"),
"start_time" : ISODate("2017-12-25T02:29:00.000Z"),
"system" : "GL",
"region" : "NY",
"order_id" : 3,
"task_type" : "px2",
"status" : false
}
当我添加新订单时,Python 脚本会在数据库中搜索具有相同 start_time 和 task_type 的现有订单,例如:
tasks_base.find_one({
"$and": [{
"start_time": plan_date.astimezone(pytz.UTC)
}, {
"task_type": px
}]
})
它可以工作,但是集合中的每个新文档都会减慢它的速度(要检查更多文档等)。
作为解决方案,我想添加task_type
和start_time
作为集合的索引。但是有一些顾虑(日期作为索引看起来有点不自然)。因此,需要建议如何正确执行(或其他想法,如何加快搜索速度)。感谢任何建议:)