? ? ? ?最近用mongodb来做一个项目,在看其关于复合索引部分的时候有一个疑惑:
“复合索引同样可用于局部属性的搜索,但必须依照索引字段顺序。比如创建索引字段顺序 "a,b,c",那么仅对 "a,b,c"、"a,b"、"a" 查询有效,而对 "b,c" 之类的组合无效。”?
来源:传说中”雨痕“的博客? http://www.rainsts.net/article.asp?id=1033
?????? 这不是跟mysql的复合索引一致么?真的是这样么?继续对这个问题的探究。
查阅mongodb的官网,有这样一段描述:
New in 1.6+
Now you can also use the compound index to service any combination of equality and range queries from the constitute fields. If the first key of the index is present in the query, that index may be selected by the query optimizer. If the first key is not present in the query, the index will only be used if hinted explicitly. While indexes can be used in many cases where an arbitrary subset of indexed fields are present in the query, as a general rule the optimal indexes for a given query are those in which queried fields precede any non queried fields.
???? 初读一遍,发现惊喜,1.6+上的新特性? 难道当前的复合索引已经支持任意复合索引的组合子集了么?怀着期待去操作了一把:
首先参看子集的版本是否1.6+:
> db.version()???????????????????????????????????????????????????????????
1.6.5
然后查看我自己的collections的复合索引:
> db.caption.getIndexes()????????????????????????????????????????????????