fix(import-export): fix import deep json overwriting variables COMPASS-5971 #3401
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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, previouslysupermarket.fruits.oranges.amount.2022-01-15
would create an empty parent atsupermarket.fruits.oranges.amount
, however this would be overridden bysupermarket.fruits.currency
creating an empty parent atsupermarket.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: