Skip to content

Commit

Permalink
pass relaxed: false to EJSON.deserialize
Browse files Browse the repository at this point in the history
  • Loading branch information
lerouxb committed Nov 9, 2023
1 parent 5a73fc1 commit 863b390
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 863b390

Please sign in to comment.