以下是MongoDB在CentOS上的索引优化策略:
explain("executionStats")
分析查询计划,识别未使用索引或低效查询。db.collection.createIndex({ field: 1 })
。db.collection.createIndex({ status: 1, orderDate: -1, amount: 1 })
。db.collection.getIndexes()
查看并删除未使用的索引。reIndex()
清理碎片,提升索引效率。cacheSizeGB
),建议设置为服务器内存的50%-70%。operationProfiling.mode: slowOp
),定位性能瓶颈。参考来源: