Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-83549

Mongodb V 7.02 Atlas not using indexes as expected

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
    • Server Triage
    • ALL

      When i was checking profiler for slow queries i found a query that is marked as slow and it makes a memory sort and scans +58000 index keys

      When i took the same query and i put it inside compass or from the shell it scans only 158 keys and no memory sort! This happens only when the query is coming from nodejs code using mongoose Version 8
      i made a new M10 atlas cluster on v6.0.5 and tested it again from the nodejs app and it was used as expected this means the issue in v7 

      here is the result for the another query

      this is the output of the profiler


      and here is the full explain for the same query from compass (match and sort)

      and here is a list of all indexes on that collection

      You will notice in profiler report and the explain of compass the same index is used in both of them!
      even though there is a big difference in examined keys

        1. compass-explain.json
          359 kB
        2. profiler-parsed-query.json
          4 kB
        3. users-indexes.json
          12 kB

            Unassigned Unassigned
            ahmed@ahmednaser.me Ahmed Naser
            0 Vote for this issue
            5 Start watching this issue