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

Shell APIs violate ECMAScript's object property order spec

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 3.5.5
    • Component/s: Shell
    • Labels:
    • Server Tooling & Methods

      If I want to add a sorting step into my aggregation pipeline which should sort the input documents according to two (or more) fields I can do so by adding a $sort stage (whose API is described here):

      { $sort: { <field1>: <sort order>, <field2>: <sort order> ... } }
      

      Given the current API the order in which the individual field sorting operations (sort by field1, then by field2, etc.) are applied is determined by the field order of the object that is assigned to the $sort property.
      But this violates the ECMAScript spec...
      E.g. ECMAScript 5 spec says that object properties are intrinsically unordered.
      And ECMAScript 6 spec defines a specific object property order, but it does not equal to the order which the object properties have been defined in (see: https://esdiscuss.org/topic/nailing-object-property-order).

      So it would be nice to have a $sort API that doesn't break the ECMAScript semantics, e.g. by using a strictly ordered data structure like an array:

      { $sort: [ [<field1>, <sort order>], [<field2>, <sort order>], ... ] }
      

            Assignee:
            backlog-server-stm Backlog - Server Tooling and Methods (STM) (Inactive)
            Reporter:
            justphil Philipp Tarasiewicz
            Votes:
            0 Vote for this issue
            Watchers:
            17 Start watching this issue

              Created:
              Updated:
              Resolved: