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

Shell APIs violate ECMAScript's object property order spec

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor - P4
    • Resolution: Unresolved
    • Affects Version/s: 3.5.5
    • Fix Version/s: Backlog
    • Component/s: Shell
    • Labels:

      Description

      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>], ... ] }
      

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated: