Skip to content

Commit 60997d1

Browse files
authored
fix: pass relaxed: false to EJSON.deserialize() so values won't be promoted COMPASS-7431 (#5090)
pass relaxed: false to EJSON.deserialize
1 parent 69070a6 commit 60997d1

File tree

10 files changed

+39
-4
lines changed

10 files changed

+39
-4
lines changed

packages/compass-import-export/src/export/export-json.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ describe('exportJSON', function () {
222222
);
223223
} catch (err) {
224224
console.log(expectedResultsPath);
225+
console.log(resultText);
225226
throw err;
226227
}
227228

packages/compass-import-export/src/import/import-json.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ describe('importJSON', function () {
132132
hasUnboundArray: false,
133133
});
134134

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

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

@@ -158,7 +158,7 @@ describe('importJSON', function () {
158158
throw err;
159159
}
160160

161-
const expectedResult = EJSON.parse(text);
161+
const expectedResult = EJSON.parse(text, { relaxed: false });
162162
expect(
163163
docs,
164164
basename.replace(/\.((jsonl?)|(csv))$/, '.imported.ejson')

packages/compass-import-export/src/import/import-json.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ export async function importJSON({
7878
throw new Error('Value is not an object');
7979
}
8080

81-
const doc = EJSON.deserialize(chunk.value);
81+
const doc = EJSON.deserialize(chunk.value as Document, {
82+
relaxed: false,
83+
});
8284
callback(null, doc);
8385
} catch (err: unknown) {
8486
processParseError({

packages/compass-import-export/test/fixtures.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const fixtures = {
5858
json: {
5959
good: path.join(__dirname, 'json', 'good.json'),
6060
complex: path.join(__dirname, 'json', 'complex.json'),
61+
promotable: path.join(__dirname, 'json', 'promotable.json'),
6162
},
6263

6364
// jsonl

packages/compass-import-export/test/json/good.imported.ejson

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@
2626
},
2727
"name": "Kochka"
2828
}
29-
]
29+
]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
_id,doubleNum
2+
1,-45
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[{
2+
"_id": {
3+
"$oid": "654d2167b25d1813f7c40749"
4+
},
5+
"doubleNum": -45
6+
}]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"paths": [["_id"], ["doubleNum"]],
3+
"docsProcessed": 1,
4+
"aborted": false,
5+
"projection": {
6+
"_id": 1,
7+
"doubleNum": 1
8+
}
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"doubleNum": {
4+
"$numberDouble": "-45.0"
5+
}
6+
}
7+
]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"doubleNum": {
4+
"$numberDouble": "-45"
5+
}
6+
}
7+
]

0 commit comments

Comments
 (0)