

Optimizing MongoDB Compound Indexes - jiryu
http://emptysquare.net/blog/optimizing-mongodb-compound-indexes/

======
Loic
About 2 years ago (time is flying) I explained how I did the same to support
range queries over "n" attributes, the method ended up being in the book "
_MongoDB, the Definitive Guide_ " by Chodorow and Dirolf (O'Reilly):

<http://chemeo.com/doc/technology>

(Search for "Indexing For High Speed Search" to skip non MongoDB related
information).

------
dkhenry
What should be added to this is the ability to tell Mongo to return an error
if your query requires a table scan. That one configuration item can be the
difference between a request returning an error and a whole site going down
for an extended period.

~~~
pbrumm
There is a config setting for that

    
    
      notablescan = true
    

[http://docs.mongodb.org/manual/reference/configuration-
optio...](http://docs.mongodb.org/manual/reference/configuration-options/)

~~~
dkhenry
Right I was saying that the author should add that to his article. Its a very
valuable configuration item and anytime your dealing with optimizing indexes
its worth enabling.

------
MartinMond
Is MongoDB actually able to combine 2 or more indices?

~~~
jiryu
No - it can only use one for a given query. But a _compound_ index like the
ones I describe in the post can index many fields.

~~~
MartinMond
Yes of course, but it's kinda slow if you have to maintain one compound index
for each possible query you're going to run, that's why I was asking.

~~~
chmod775
Nope, you can use the compound index 'a,b,c' to query over the following
fields:

    
    
        a
        a.b
        a,b,c
    

The manual actually explains it like that.

