Prefer update documents instead of inserting

This commit is contained in:
2022-03-13 14:34:57 +03:00
parent ff2cc92b5f
commit 9e216f821f

View File

@@ -20,12 +20,12 @@ async function initDB () {
const setPrice = await item.set.getPrice()
if (partsPrice < setPrice) {
const scanResult = new models.ScanResult({
name: item.name,
partsPrice,
setPrice
})
scanResult.save()
models.ScanResult.findOneAndUpdate(
{ name: item.name },
{ partsPrice, setPrice },
{ upsert: true },
() => {}
)
}
}
})()