Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-578

Order of sort fields is lost for numeric field names

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

      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:
            christkv Christian Amor Kvalheim
            Reporter:
            skleeschulte Stefan Kleeschulte
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: