mogno export+import uses EJSON

This commit is contained in:
Jan Prochazka
2024-08-26 15:09:44 +02:00
parent 62de736bce
commit d54b47f713
2 changed files with 18 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
const ObjectId = require('mongodb').ObjectId;
const { getLogger } = global.DBGATE_PACKAGES['dbgate-tools'];
const { EJSON } = require('bson');
const logger = getLogger('mongoBulkInsert');
@@ -26,7 +27,7 @@ function createBulkInsertStream(driver, stream, pool, name, options) {
...row,
};
}
writable.buffer.push(row);
writable.buffer.push(EJSON.deserialize(row));
};
writable.checkStructure = async () => {

View File

@@ -245,8 +245,23 @@ const driver = {
const db = await getScriptableDb(pool);
exprValue = func(db, ObjectId.createFromHexString);
const pass = new stream.PassThrough({
objectMode: true,
highWaterMark: 100,
});
exprValue
.forEach((row) => pass.write(transformMongoData(row)))
.then(() => {
pass.end();
// pass.end(() => {
// pass.emit('end');
// })
});
return pass;
// return directly stream without header row
return exprValue.stream();
// return exprValue.stream();
// pass.write(structure || { __isDynamicStructure: true });
// exprValue.on('data', (row) => pass.write(row));