Examine where an empty sorting spec is a valid use case and where it should be disallowed

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query Optimization
    • None
    • 3
    • TBD
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Consider where an empty sort spec is a valid use case and where it should be disallowed.

      For example, here, empty sort specs are disallowed:

      • SERVER-96579
        db.nodata.aggregate([{$group: {_id: "$a", o: {$top: {output: 'a', sortBy: {}}}}}]);
        MongoServerError[Location9657900]: Value for 'sortBy' must be a non-empty object
        
      • rs0 [direct: primary] test> db.test.aggregate([{$match: {a: {$gte: 0}}}, {$sort: {}}])
        MongoServerError[Location15976]: $sort stage must have at least one sort key
        

      Whereas here, they are a valid query:

      • rs0 [direct: primary] test> db.test.find().sort({})
        [
          { _id: ObjectId('68790b382cd1e62966ffa76e'), a: 0, b: 0 },
          ...
        ]
        

      The inspection should be done on a case-by-case basis.

              Assignee:
              Unassigned
              Reporter:
              Tymoteusz Ślepowroński
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated: