Skip to content

Commit

Permalink
fix: pass relaxed: false to EJSON.deserialize() so values won't be pr…
Browse files Browse the repository at this point in the history
…omoted COMPASS-7431 (#5090)

pass relaxed: false to EJSON.deserialize
  • Loading branch information
lerouxb authored Nov 10, 2023
1 parent 69070a6 commit 60997d1
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ describe('exportJSON', function () {
);
} catch (err) {
console.log(expectedResultsPath);
console.log(resultText);
throw err;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/compass-import-export/src/import/import-json.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ describe('importJSON', function () {
hasUnboundArray: false,
});

const docs = await dataService.find(ns, {});
const docs = await dataService.find(ns, {}, { promoteValues: false });

expect(docs).to.have.length(totalRows);

Expand All @@ -158,7 +158,7 @@ describe('importJSON', function () {
throw err;
}

const expectedResult = EJSON.parse(text);
const expectedResult = EJSON.parse(text, { relaxed: false });
expect(
docs,
basename.replace(/\.((jsonl?)|(csv))$/, '.imported.ejson')
Expand Down
4 changes: 3 additions & 1 deletion packages/compass-import-export/src/import/import-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ export async function importJSON({
throw new Error('Value is not an object');
}

const doc = EJSON.deserialize(chunk.value);
const doc = EJSON.deserialize(chunk.value as Document, {
relaxed: false,
});
callback(null, doc);
} catch (err: unknown) {
processParseError({
Expand Down
1 change: 1 addition & 0 deletions packages/compass-import-export/test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const fixtures = {
json: {
good: path.join(__dirname, 'json', 'good.json'),
complex: path.join(__dirname, 'json', 'complex.json'),
promotable: path.join(__dirname, 'json', 'promotable.json'),
},

// jsonl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
},
"name": "Kochka"
}
]
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_id,doubleNum
1,-45
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[{
"_id": {
"$oid": "654d2167b25d1813f7c40749"
},
"doubleNum": -45
}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"paths": [["_id"], ["doubleNum"]],
"docsProcessed": 1,
"aborted": false,
"projection": {
"_id": 1,
"doubleNum": 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"doubleNum": {
"$numberDouble": "-45.0"
}
}
]
7 changes: 7 additions & 0 deletions packages/compass-import-export/test/json/promotable.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"doubleNum": {
"$numberDouble": "-45"
}
}
]

0 comments on commit 60997d1

Please sign in to comment.