0

Index 1:

{
  A: 1
}

Index 2:

{
  B: 1
}

query:

db.col.aggregate([
  {
    $match: {
      $or: [
        A: { $eq: 100 },
        B: { $eq: 100 },
      ]
    }
  }
])

Will mongodb use both indexes in this query?

  • 4
    Have you tried it? We've mentioned checking `explain()` output I'm a number of your recent questions. Should be pretty quick to run the command and see what plans are considered (`rejectedPlans` field) and chosen (`winningPlan`). The `$or documentation page also has details about index usage – user20042973 Dec 31 '22 at 02:41

1 Answers1

0

according to docs:

https://www.mongodb.com/docs/manual/reference/operator/query/or/

it will use both indexes.