Aggregate sort son't respect order of passed in columns

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Works as Designed
    • Priority: Major - P3
    • None
    • Affects Version/s: 3.6.1
    • Component/s: None
    • None
    • Environment:
      Windows 10, Python 2.7.12
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      self.DB.killmails.aggregate([
            {'$match': {'date.year': timestamp.year, 'date.month': timestamp.month}},
            {'$unwind': '$attackers_processed.wingspan'},
            {'$group': {
              '_id': {
                  'character_id': '$attackers_processed.wingspan.character_id',
                  'ship_type_id': '$attackers_processed.wingspan.ship_type_id',
                  'weapon_type_id': '$attackers_processed.wingspan.weapon_type_id'
              },
              'character_id': {'$first': '$attackers_processed.wingspan.character_id'},
              'value': {'$sum': 1},
              'optional': {'$sum': '$zkb.totalValue'}
            }},
            {'$sort': {'value': -1, 'optional': -1}},
          ])
      

      Code above should sort on `value` then on `optional`, but it will actually sort on `optional` first and then sort on `value`.

      {u'character_id': 95009795, u'_id': {u'character_id': 95009795, u'weapon_type_id': 24507, u'ship_type_id': 33820}, u'optional': 5526483026.83, u'value': 2}
      {u'character_id': 90999289, u'_id': {u'character_id': 90999289, u'weapon_type_id': 27345, u'ship_type_id': 12032}, u'optional': 4024211778.699999, u'value': 11}
      {u'character_id': 95009795, u'_id': {u'character_id': 95009795, u'weapon_type_id': 24519, u'ship_type_id': 12034}, u'optional': 3761105696.78, u'value': 16}
      {u'character_id': 90761793, u'_id': {u'character_id': 90761793, u'weapon_type_id': 2185, u'ship_type_id': 29990}, u'optional': 3662828785.9300003, u'value': 2}
      {u'character_id': 90761793, u'_id': {u'character_id': 90761793, u'weapon_type_id': 24486, u'ship_type_id': 29990}, u'optional': 2989744596.8, u'value': 4}
      

            Assignee:
            Bernie Hackett
            Reporter:
            Rustam @Second_Fry Gubaydullin [X]
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: