Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-1519

Explain does not necessarily retain sortPattern ordering

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.1.1, 3.6.1
    • Component/s: JSON
    • None

      Summary

      I noticed this while looking into SERVER-34265, it looks like for some sortpatterns (possibly numeric fieldnames?) the correct ordering the of fields in the sortPattern may not be maintained.

      pp.pprint(c.find({}).sort([
              ("11", pymongo.DESCENDING),
              ("10", pymongo.ASCENDING)]).explain())
      

      returns

                         u'winningPlan': {u'inputStage': {u'inputStage': {u'direction': u'forward',
                                                                          u'stage': u'COLLSCAN'},
                                                          u'stage': u'SORT_KEY_GENERATOR'},
                                          u'sortPattern': {u'10': 1, u'11': -1},
                                          u'stage': u'SORT'}},
      

      The sort is correctly applied on the server-side, and the results of the query are appropriately ordered.

      Additionally, I examined the Java driver's explain output, and it was fine, suggesting that the issue is in the python driver.

      Standalone Repro
      import pymongo
      import pprint
      
      pp = pprint.PrettyPrinter()
      
      client = pymongo.MongoClient('localhost', 27017)
      
      db = client.test
      c = db.foo
      
      c.insert({"10": 2, "11": 2})
      c.insert({"10": 2, "11": 3})
      c.insert({"10": 2, "11": 1})
      c.insert({"10": 1, "11": 2})
      c.insert({"10": 3, "11": 2})
      
      for doc in c.find({}).sort([
              ("11", pymongo.DESCENDING),
              ("10", pymongo.ASCENDING)]):
          print(doc)
      
      pp.pprint(c.find({}).sort([
              ("11", pymongo.DESCENDING),
              ("10", pymongo.ASCENDING)]).explain())
      

            Assignee:
            shane.harvey@mongodb.com Shane Harvey
            Reporter:
            kelsey.schubert@mongodb.com Kelsey Schubert
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: