And query for mongodb

  mongodb, question

Assuming db.find({a:1,b:1,c:1}), there are 1 million documents that meet condition a, 700,000 documents that meet condition b, and 300,000 documents that meet condition c, all three fields have no index and are scanned across the table, then find({a:1,b:1,c:1}) and find ({c: 1, b: 1, a

  • If there is no index, there is only one execution plan: COLLSCAN (full table scan), so it must be to take out each record and compare it with ABC to see if it is satisfied and then get the result, regardless of how many conditions there are.
  • Under the condition of partial coverage of indexes, the system will pick the index it considers the best, and scan the obtained documents on its results to see if other conditions are met.
  • If the index can cover all the conditions, then the index can directly give the result (optimal case).

Either way, there is no such plan as you want to check one condition first, another condition, and then … it is too wasteful. So the order of the conditions is actually irrelevant.