本文介绍了有了新的索引交集功能,什么时候复合索引在MongoDB 2.6中仍然有用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Mongo 2.6引入了索引交集.在我看来,使用复合索引可以实现任何目标,使用索引交集可以更轻松地实现任何目标,并且具有更大的灵活性(因为它可以支持更多类型的查询).但是,Mongo的文档说:

Mongo 2.6 introduced Index Intersection. It appears to me that whatever can be achieved using Compound Index, can be more easily achieved using Index Intersection, and with greater flexibility (as it could support more types of queries). However, Mongo's documentation says that:

然后继续说明相对于索引交集使用复合索引的缺点.我不明白使用这种索引而不是让mongo与多个索引相交以完成查询的优点是什么.

Then it goes on explaining the disadvantages of using compound index relatively to index intersection. I could not understand what is the advantage of using such index instead of letting mongo intersect several indexes to fulfill the query.

编辑:我建议阅读链接 @Sammaye在他的答案中提供了由Mongo开发人员David Storch进行的索引交叉与复合索引的详细说明.底线:

Edit: I recommended reading the link @Sammaye provided in his answer for detailed explanation of index intersection vs. compound index by Mongo's dev David Storch. Bottom line:

推荐答案

有两点需要回答:

  • 索引交集不能代替复合索引,而仅仅是像$where那样在您没有真正选择的情况下使用.索引相交不是在集合中查找文档的最快,也不是可扩展性最高的方法,因此您必须注意使用了多少个相交.

    • Index intersectioning is not a replacement for compound indexes, but merely, like $where to be used when you have no real choice. Index intersectioning is not the fastest, nor most scalable way to find documents within a collection so you must be careful about just how much intersections you use.

      还应注意,MongoDB可以相交的索引确实存在限制: http://docs.mongodb.org/manual/core/index-intersection/#index-intersection-and-sort

      It is also good to note there are limitations on exactly what indexes MongoDB can intersect: http://docs.mongodb.org/manual/core/index-intersection/#index-intersection-and-sort

      这篇关于有了新的索引交集功能,什么时候复合索引在MongoDB 2.6中仍然有用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 12:40