Pergunta

What are the advantages we get from compound indexes. I mean suppose we have a collection, in which I have to index over 2 fields say key1 and key2. How different is it from having a compound index {key1:1, key2:1}. Whats the problem with having 2 separate indexes. Can't mongodb make use of 2 or more indexes to satisfy a query.

Foi útil?

Solução

As at MongoDB 2.2:

Every query, including update operations, use one and only one index. The query optimizer selects the index empirically by occasionally running alternate query plans and by selecting the plan with the best response time for each query type.

An exception to the above rule is $or queries; each clause is executed in parallel and can use a separate index.

For more information see:

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top