Order of sort fields is lost for numeric field names

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Major - P3
    • 2.0.46
    • Affects Version/s: 2.0.45
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Order of sort fields is lost for numeric field names. Consider this example:

      {{collection.find({},

      { sort: [['2', 1], ['1', 1]] }

      )}}

      The expected result would be to first sort on field 2, then sort on field 1. Instead, it is first sorted on field 1, then on field 2.

      The reason is that the driver converts the array of sort fields into an object in the method formattedOrderClause in utils.js (called at http://mongodb.github.io/node-mongodb-native/2.0/api/lib_collection.js.html#line346). Here the order is lost, because numeric property names are not necessarily enumerated in insertion order:

      ECMA-262 does not specify enumeration order. The de facto standard is to match
      insertion order, which V8 also does, but with one exception:

      V8 gives no guarantees on the enumeration order for array indices (i.e., a property
      name that can be parsed as a 32-bit unsigned integer).

      (https://code.google.com/p/v8/issues/detail?id=164)

            Assignee:
            Christian Amor Kvalheim
            Reporter:
            Stefan Kleeschulte
            None
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: