[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 Created: 08/Sep/21  Updated: 29/Oct/23  Resolved: 20/Jun/22

Status: Closed
Project: Compass
Component/s: Import/Export
Affects Version/s: None
Fix Version/s: 1.32.3

Type: Bug Priority: Major - P3
Reporter: Sergey Petushkov Assignee: Le Roux Bodenstein
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to COMPASS-4548 Compass JSON import object with numbe... Closed
Story Points: 3
Documentation Changes: Not Needed
Sprint: 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



 Comments   
Comment by Githook User [ 06/Jul/22 ]

Author:

{'name': 'Le Roux Bodenstein', 'email': 'lerouxb@gmail.com', 'username': 'lerouxb'}

Message: fix(import): pre-create an empty object before creating its properties COMPASS-5076 (#3184)

  • pre-create an empty object before creating its properties
  • typescript
  • unknown
Comment by Githook User [ 06/Jul/22 ]

Author:

{'name': 'Le Roux Bodenstein', 'email': 'lerouxb@gmail.com', 'username': 'lerouxb'}

Message: fix(import): pre-create an empty object before creating its properties COMPASS-5076 (#3184)

  • pre-create an empty object before creating its properties
  • typescript
  • unknown
Comment by Githook User [ 30/Jun/22 ]

Author:

{'name': 'Le Roux Bodenstein', 'email': 'lerouxb@gmail.com', 'username': 'lerouxb'}

Message: fix(import): pre-create an empty object before creating its properties COMPASS-5076 (#3184)

  • pre-create an empty object before creating its properties
  • typescript
  • unknown
Comment by Githook User [ 29/Jun/22 ]

Author:

{'name': 'Le Roux Bodenstein', 'email': 'lerouxb@gmail.com', 'username': 'lerouxb'}

Message: fix(import): pre-create an empty object before creating its properties COMPASS-5076 (#3184)

  • pre-create an empty object before creating its properties
  • typescript
  • unknown
Comment by Githook User [ 26/Jun/22 ]

Author:

{'name': 'Le Roux Bodenstein', 'email': 'lerouxb@gmail.com', 'username': 'lerouxb'}

Message: fix(import): pre-create an empty object before creating its properties COMPASS-5076 (#3184)

  • pre-create an empty object before creating its properties
  • typescript
  • unknown
Comment by Githook User [ 22/Jun/22 ]

Author:

{'name': 'Le Roux Bodenstein', 'email': 'lerouxb@gmail.com', 'username': 'lerouxb'}

Message: fix(import): pre-create an empty object before creating its properties COMPASS-5076 (#3184)

  • pre-create an empty object before creating its properties
  • typescript
  • unknown
Comment by Githook User [ 22/Jun/22 ]

Author:

{'name': 'Le Roux Bodenstein', 'email': 'lerouxb@gmail.com', 'username': 'lerouxb'}

Message: fix(import): pre-create an empty object before creating its properties COMPASS-5076 (#3184)

  • pre-create an empty object before creating its properties
  • typescript
  • unknown
Comment by Githook User [ 20/Jun/22 ]

Author:

{'name': 'Le Roux Bodenstein', 'email': 'lerouxb@gmail.com', 'username': 'lerouxb'}

Message: fix(import): pre-create an empty object before creating its properties COMPASS-5076 (#3184)

  • pre-create an empty object before creating its properties
  • typescript
  • unknown
Comment by Githook User [ 18/Jun/22 ]

Author:

{'name': 'Le Roux Bodenstein', 'email': 'lerouxb@gmail.com', 'username': 'lerouxb'}

Message: fix(import): pre-create an empty object before creating its properties COMPASS-5076 (#3184)

  • pre-create an empty object before creating its properties
  • typescript
  • unknown
Generated at Wed Feb 07 22:38:22 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.