Compound indexes support queries on any prefix of the index fields. Index prefixes are the beginning subset of indexed fields. For example, given the index { a: 1, b: 1, c: 1 }, both { a: 1 } and { a: 1, b: 1 }are prefixes of the index.
Given the following index:
{ "item": 1, "location": 1, "stock": 1 }
MongoDB can use this index to support queries that include:
- the item field,
- the item field and the location field,
- the item field and the location field and the stock field, or
- only the item and stock fields; however, this index would be less efficient than an index on onlyitem and stock.
MongoDB cannot use this index to support queries that include:
- only the location field,
- only the stock field, or
- only the location and stock fields.
本文解释了MongoDB中复合索引的前缀查询概念,包括哪些字段组合可以被有效利用,以及在不同字段组合查询时索引的有效性和效率。
1266

被折叠的 条评论
为什么被折叠?



