How to optimize $in query performance in mongodb using an index?

Viewed 109

I am doing an $in query in a mongodb cluster in my application. Below is an extract from the query details shown in mongodb atlas for this query.

{
  "command": {
    "find": "orders",
    "filter": {
      "owner": "testowner",
      "reference": {
        "$in": [
          "123",
          "456",
          "... about 1000 more refs"
        ]
      }
    }
  },
  "planSummary": "IXSCAN { owner: 1, reference: 1, createdTimestamp: -1 }",
  "keysExamined": 10841,
  "docsExamined": 101,
  "hasSortStage": true,
  "fromMultiPlanner": true,
  "numYields": 393,
  "nreturned": 101,
  "reslen": 53913,
  "durationMillis": 6820
}

Even though the query has used my index, keys examined to docs returned ratio is high, and the query has taken about 7 seconds.

Does anyone have any suggestions on how I can improve the performance of this query?

0 Answers
Related