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

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 1.32.3
    • Import/Export
    • None
    • 3
    • Not Needed
    • Iteration Dolphin

    Description

      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

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: