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

Enabling encryption loses sort and createIndexes key order

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Critical - P2 Critical - P2
    • 4.9.0
    • Affects Version/s: None
    • Component/s: None
    • 0
    • Not Needed

      Description

      Javascript objects do not maintain chronological key insertion order if the keys are array index-like numerical strings. This means that sorts and indexes can have important key ordering information lost if those APIs are used with js objects. We fixed this issue with sort in NODE-3174 but it is still broken for indexes but a fix is planned in NODE-3517.
      Unfortunately, both are broken by our use of FLE, the encrypt method serializes a js object to bytes to pass to the native layer and deserializes the bson that has been modified. This process deserializes what may have been a JS Map (to preserve key order) to a JS object which loses the key order information if the key format is numeric.

      Reproduction

      // where coll is a collection from a client that has autoEncryption options
      const sort = [
        ['1', 1],
        ['0', 1]
      ];
      const index = sort;
      await coll.findOne({}, { sort });
      await coll.createIndex(index, { name: 'myIndex' });
      

      The find CommandStartedEvent

      { command: { sort: { '0': new Int32(1), '1': new Int32(1) } } }
      

      The index created on the server

      { v: 2, key: { '0': 1, '1': 1 }, name: 'myIndex' }
      

            Assignee:
            neal.beeken@mongodb.com Neal Beeken
            Reporter:
            neal.beeken@mongodb.com Neal Beeken
            Neal Beeken
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: