top | item 4627969

Optimizing MongoDB Compound Indexes

46 points| jiryu | 13 years ago |emptysquare.net

11 comments

order

Loic|13 years ago

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|13 years ago

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.

lucian1900|13 years ago

You can ask it to explain what it did, just like you'd ask for the last error. Then in your app enforce whatever rules related to indexes you wish.

MartinMond|13 years ago

Is MongoDB actually able to combine 2 or more indices?

jiryu|13 years ago

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.