除了基本的单字段索引外,MongoDB还提供了高级索引策略——复合索引排序(ESR规则)、覆盖查询、部分索引/稀疏索引、TTL索引等等——这些策略对查询性能的影响极大。掌握它们是MongoDB大规模性能优化的关键。
复合索引的ESR规则
For a compound index supporting a query with Equality, Sort, and Range conditions,
order the fields: EQUALITY → SORT → RANGE (the ESR rule).
db..({ : , : , : });
db..({ : , : { : } }).({ : });
