Why is mongo query not using indexes?

with the below pipeline

 "pipeline": [
        "$match": {
          "uid": "cdc67cf2-0c23-4d32-b103-f78503824b18"
        "$sort": {
          "score": -1,
          "_id": 1
        "$skip": 0
        "$limit": 100
, "collation": {
      "locale": "en"

and index - {uid:1, score: -1, _id:1}

My execution plan shows up -
“planSummary”: “COLLSCAN”,
“keysExamined”: 0,
“docsExamined”: 72719,
“hasSortStage”: true,
“cursorExhausted”: true,
“numYields”: 74,
“nreturned”: 100,

WHY is the above query not using the index? What is wrong with the index?

The above looks like a pipeline inside a $lookup stage.

Please share the whole aggregation, including the code that calls the aggregation.

Please share the output of getIndexes() from both the starting collection and the looked up collection.

Please share the whole explain plan.

1 Like

Hi @steevej the problem my query not taking indexes was that the index I created was not with collation option. But my query has collation usage in the aggregation. So creating new index with the collation strategy worked for me.
Thanks for taking time to reply.


This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.