Uploaded image for project: 'Compass '
  1. Compass
  2. COMPASS-5076

Importing a document with mixed numeric and string keys causes the object to be converted to array when numeric keys are first in the list of keys

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.32.3
    • Affects Version/s: None
    • Component/s: Import/Export
    • None
    • 3
    • Not Needed
    • Iteration Dolphin

      Problem Statement/Rationale

      Importing from JSON file a document that looks something like this:

      {
        "foo": { "1": 1, "a": "a" }
      }
      

      will result in the property foo being converted to the array during the import

      Steps to Reproduce

      Create a json file with documents that have mixed number-like and string keys

      Expected Results

      Document is uploaded, all values are present in the imported documents, objects are still objects

      Actual Results

      If a document has mixed keys, it will be converted to an array and all string keys will be lost

      Additional Notes

      Here's the root cause: https://github.com/mongodb-js/compass/blob/0c6483f7aaea2d9e00a6d09520428111fc808b09/packages/compass-import-export/src/utils/import-apply-types-and-projection.js#L66

      If this set encounters a path that ends in a number-like key, it will create an array, if not, it will create an object. If an object has mixed keys, first one will always be a number-like one in this part of the code

            Assignee:
            leroux.bodenstein@mongodb.com Le Roux Bodenstein
            Reporter:
            sergey.petushkov@mongodb.com Sergey Petushkov
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: