ability to create string mongo IDs when importing

This commit is contained in:
Jan Prochazka
2021-12-09 09:10:07 +01:00
parent 5cc78c4e50
commit 82ae588d9a
7 changed files with 50 additions and 9 deletions

View File

@@ -1,3 +1,5 @@
const ObjectId = require('mongodb').ObjectId;
function createBulkInsertStream(driver, stream, pool, name, options) {
const collectionName = name.pureName;
const db = pool.__getDatabase();
@@ -19,11 +21,17 @@ function createBulkInsertStream(driver, stream, pool, name, options) {
)
return;
}
if (options.createStringId) {
row = {
_id: new ObjectId().toString(),
...row,
}
}
writable.buffer.push(row);
};
writable.checkStructure = async () => {
if (options.dropIfExists || options.truncate) {
if (options.dropIfExists) {
console.log(`Dropping collection ${collectionName}`);
await db.collection(collectionName).drop();
}

View File

@@ -59,7 +59,9 @@ const driver = {
? `mongodb://${user}:${password}@${server}:${port}`
: `mongodb://${server}:${port}`;
const options = {};
const options = {
useUnifiedTopology: true,
};
if (ssl) {
options.tls = true;
options.tlsCAFile = ssl.ca;

View File

@@ -44,6 +44,16 @@ const driver = {
return ['server', 'port', 'user', 'password', 'defaultDatabase', 'singleDatabase'].includes(field);
},
importExportArgs: [
{
type: 'checkbox',
name: 'createStringId',
label: 'Create string _id attribute',
apiName: 'createStringId',
direction: 'target',
},
],
getCollectionUpdateScript(changeSet) {
let res = '';
for (const insert of changeSet.inserts) {