索引优化
db.users.createIndex({username: 1})。db.orders.createIndex({userId: 1, orderDate: -1})。reIndex() 重建索引,删除冗余索引。查询语句优化
db.users.find({}, {name: 1, email: 1})。skip() 和 limit(),避免大数据集全量返回。explain("executionStats") 分析查询计划,避免全表扫描。硬件与配置优化
mongod.conf 中的 wiredTiger.cacheSizeGB(建议设为物理内存的50%~80%)。架构优化
监控与维护
mongostat/mongotop 或第三方工具(如PMM)监控性能。