Skip to content

Conversation

Anemy
Copy link
Member

@Anemy Anemy commented Aug 29, 2022

COMPASS-5971
https://github.com/mongodb-js/compass/issues/3373

Previously, when importing json documents with deep nested fields which have values alongside subdocuments in a subdocument, a bug would cause Compass to overwrite the parent. This PR fixes the bug so that all of the fields are correctly accounted for. (Example failing json document below, the amount fields are all overridden).

Previously in dotnotation.ts we were creating an empty object for the direct parent for a value when a value arrises. This pr updates it so that we create an empty object at the topmost parent and work our way in so that we don't possibly override existing parents. (With the example before, previously supermarket.fruits.oranges.amount.2022-01-15 would create an empty parent at supermarket.fruits.oranges.amount, however this would be overridden by supermarket.fruits.currency creating an empty parent at supermarket.fruits. These changes make it so that we iteratively create an empty object at each parent stage and don't skip possible parents which cause overriding errors and possible data loss.

Example test document:

[
  {
    "abc": "123",
    "supermarket": {
      "def": "456",
      "fruits": {
        "updated": 2,
        "oranges": {
          "amount": {
            "2022-01-15": 1.66,
            "2022-02-16": 1.22,
            "2022-03-13": 1.11,
            "2022-04-14": 7.69,
          },
        },
        "apples": {
          "amount": {
            "2022-01-15": 3.47,
            "2022-02-14": 4.18,
            "2022-03-15": 4.18,
          },
        },
        "currency": "usd",
      },
    },
    "test": "123",
  }
]

@Anemy Anemy removed the wip label Aug 30, 2022
Copy link
Contributor

@lerouxb lerouxb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@Anemy Anemy merged commit 153cc8b into main Aug 30, 2022
@Anemy Anemy deleted the COMPASS-5971-fix-import-deep-json branch August 30, 2022 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants