Mongodb using a less efficient index

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?

+4
source share
2 answers

Note1:

2 , RunID RunID + JobType. RunID + JobType + Info; RunID RunID + JobType, info here:

, , , .

, mongo .

2:

hint, :

db.getCollection('Jobs').find().hint({RunID:1, JobType:1, Info:1})
+2

Sergiu Sammaye, , , :

  • RunID, RunID , mongodb , RunID.

  • $or :

$ MongoDB , , MongoDB . , MongoDB $ , $ . , MongoDB .

, RunID , : JobType Info, JobType , , Info, -

{ "JobType": 1.0, "Info": 1.0}

mongodb , .

+1

Source: https://habr.com/ru/post/1653660/


All Articles