Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions modules/module-mongodb/src/replication/MongoRelation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ function filterJsonData(data: any, depth = 0): any {
} else if (data instanceof mongo.Decimal128) {
return data.toString();
} else if (data instanceof mongo.MinKey || data instanceof mongo.MaxKey) {
return data._bsontype;
} else if (data instanceof mongo.BSONRegExp) {
return JSON.stringify({ pattern: data.pattern, options: data.options });
return null;
} else if (data instanceof RegExp) {
return { pattern: data.source, options: data.flags };
} else if (Array.isArray(data)) {
return data.map((element) => filterJsonData(element, depth + 1));
} else if (ArrayBuffer.isView(data)) {
Expand Down
45 changes: 41 additions & 4 deletions modules/module-mongodb/test/src/mongo_test.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,18 @@ describe('mongo data types', () => {
objectId: mongo.ObjectId.createFromHexString('66e834cc91d805df11fa0ecb'),
regexp: new mongo.BSONRegExp('test', 'i'),
minKey: new mongo.MinKey(),
maxKey: new mongo.MaxKey()
maxKey: new mongo.MaxKey(),
symbol: new mongo.BSONSymbol('test'),
js: new mongo.Code('testcode'),
js2: new mongo.Code('testcode', { foo: 'bar' }),
pointer: new mongo.DBRef('mycollection', mongo.ObjectId.createFromHexString('66e834cc91d805df11fa0ecb')),
pointer2: new mongo.DBRef(
'mycollection',
mongo.ObjectId.createFromHexString('66e834cc91d805df11fa0ecb'),
'mydb',
{ foo: 'bar' }
),
undefined: undefined
}
]);
}
Expand Down Expand Up @@ -62,7 +73,11 @@ describe('mongo data types', () => {
objectId: [mongo.ObjectId.createFromHexString('66e834cc91d805df11fa0ecb')],
regexp: [new mongo.BSONRegExp('test', 'i')],
minKey: [new mongo.MinKey()],
maxKey: [new mongo.MaxKey()]
maxKey: [new mongo.MaxKey()],
symbol: [new mongo.BSONSymbol('test')],
js: [new mongo.Code('testcode')],
pointer: [new mongo.DBRef('mycollection', mongo.ObjectId.createFromHexString('66e834cc91d805df11fa0ecb'))],
undefined: [undefined]
}
]);
}
Expand Down Expand Up @@ -97,7 +112,13 @@ describe('mongo data types', () => {
timestamp: 1958505087099n,
regexp: '{"pattern":"test","options":"i"}',
minKey: null,
maxKey: null
maxKey: null,
symbol: 'test',
js: '{"code":"testcode","scope":null}',
js2: '{"code":"testcode","scope":{"foo":"bar"}}',
pointer: '{"collection":"mycollection","oid":"66e834cc91d805df11fa0ecb","fields":{}}',
pointer2: '{"collection":"mycollection","oid":"66e834cc91d805df11fa0ecb","db":"mydb","fields":{"foo":"bar"}}',
undefined: null
});
}

Expand Down Expand Up @@ -130,7 +151,14 @@ describe('mongo data types', () => {
expect(transformed[3]).toMatchObject({
_id: 10n,
objectId: '["66e834cc91d805df11fa0ecb"]',
timestamp: '[1958505087099]'
timestamp: '[1958505087099]',
regexp: '[{"pattern":"test","options":"i"}]',
symbol: '["test"]',
js: '[{"code":"testcode","scope":null}]',
pointer: '[{"collection":"mycollection","oid":"66e834cc91d805df11fa0ecb","fields":{}}]',
minKey: '[null]',
maxKey: '[null]',
undefined: '[null]'
});
}

Expand Down Expand Up @@ -245,14 +273,23 @@ describe('mongo data types', () => {
{ name: 'int2', sqlite_type: 4, internal_type: 'Integer' },
{ name: 'int4', sqlite_type: 4, internal_type: 'Integer' },
{ name: 'int8', sqlite_type: 4, internal_type: 'Long' },
// We can fix these later
{ name: 'js', sqlite_type: 2, internal_type: 'Object' },
{ name: 'js2', sqlite_type: 2, internal_type: 'Object' },
{ name: 'maxKey', sqlite_type: 0, internal_type: 'MaxKey' },
{ name: 'minKey', sqlite_type: 0, internal_type: 'MinKey' },
{ name: 'nested', sqlite_type: 2, internal_type: 'Object' },
{ name: 'null', sqlite_type: 0, internal_type: 'Null' },
{ name: 'objectId', sqlite_type: 2, internal_type: 'ObjectId' },
// We can fix these later
{ name: 'pointer', sqlite_type: 2, internal_type: 'Object' },
{ name: 'pointer2', sqlite_type: 2, internal_type: 'Object' },
{ name: 'regexp', sqlite_type: 2, internal_type: 'RegExp' },
// Can fix this later
{ name: 'symbol', sqlite_type: 2, internal_type: 'String' },
{ name: 'text', sqlite_type: 2, internal_type: 'String' },
{ name: 'timestamp', sqlite_type: 4, internal_type: 'Timestamp' },
{ name: 'undefined', sqlite_type: 0, internal_type: 'Null' },
{ name: 'uuid', sqlite_type: 2, internal_type: 'UUID' }
]
}
Expand Down
Loading