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();
}