选择合适索引类型
db.collection.createIndex({ field: 1 })。db.collection.createIndex({ content: "text" })。db.collection.createIndex({ location: "2dsphere" })。避免过度索引
db.collection.aggregate([{$indexStats: {}}])监控索引使用情况,定期清理。优化索引使用方式
定期维护索引
db.collection.reIndex()。结合查询优化
explain()分析查询计划,确保查询命中索引。硬件与配置协同
wiredTiger.cacheSizeGB参数,确保索引数据驻留内存。参考来源: