Forces file registration to avoid registering a file that already exists in an atomic fasion

pull/443/head
Isaac Abadi 4 years ago
parent 9e60d9fe3e
commit ce3d540633

@ -623,7 +623,22 @@ exports.insertRecordIntoTable = async (table, doc, replaceFilter = null) => {
return true; return true;
} }
if (replaceFilter) await database.collection(table).deleteMany(replaceFilter); if (replaceFilter) {
const output = await database.collection(table).bulkWrite([
{
deleteMany: {
filter: replaceFilter
}
},
{
insertOne: {
document: doc
}
}
]);
logger.debug(`Inserted doc into ${table} with filter: ${JSON.stringify(replaceFilter)}`);
return !!(output['result']['ok']);
}
const output = await database.collection(table).insertOne(doc); const output = await database.collection(table).insertOne(doc);
logger.debug(`Inserted doc into ${table}`); logger.debug(`Inserted doc into ${table}`);

Loading…
Cancel
Save