I use mongodb 2.6and I have the following query:
db.getCollection('Jobs').find(
{ $and: [ { RunID: { $regex: ".*_0" } },
{ $or: [ { JobType: "TypeX" },
{ JobType: "TypeY" },
{ JobType: "TypeZ" },
{ $and: [ { Info: { $regex: "Weekly.*" } }, { JobType: "YetAnotherType" } ] } ] } ] })
I have three different indices: RunID, RunID + JobType, RunID + JobType + Info. Mongo always uses an index containing only RunID, although other indexes are more likely to give faster results, even sometimes using an index consisting of RunID + StartTime, while StartTime is not even included in the list of fields used, any idea why it selects this index?
source
share