MongoDB索引优化策略核心围绕提升查询效率、降低维护成本,主要包括以下方面:
{status: 1, order_date: -1, amount: 1}。explain()分析:通过executionStats监控索引命中率、扫描文档数等指标。reIndex()消除碎片,优化存储结构。关键命令示例:
db.orders.createIndex({status: 1, order_date: -1})。db.orders.find({status: "shipped"}).explain("executionStats")。db.orders.dropIndex("status_order_date_idx")。通过以上策略,可显著提升MongoDB查询性能,平衡读写负载。