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

$sort in aggregate is super slow

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.4.6
    • Component/s: Aggregation Framework
    • Labels:
      None
    • ALL

      I have a collection with about 75.000 docs

      Indexes:
      ad.guid_1
      unitUuid_1

      This query takes about 1-2 milliseconds and gives 1 hit:

      db.getCollection('xxx').aggregate([
          { $match: { "ad.guid": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" } }
      ])
      

      This query takes about 180 milliseconds and gives 1 hit:

      db.getCollection('xxx').aggregate([
          { $match: { "ad.guid": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" } },
          { $sort: { "unitUuid": 1 } }
      ])
      

      Why is it so slow with $sort?

            Assignee:
            mark.agarunov Mark Agarunov
            Reporter:
            jesperbendtsen83@gmail.com Jesper Erik Bendtsen
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: