From 9e216f821f76d167627d6503a0d75b61af78932a Mon Sep 17 00:00:00 2001 From: Anatoly Date: Sun, 13 Mar 2022 14:34:57 +0300 Subject: [PATCH] Prefer update documents instead of inserting --- gather/src/index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gather/src/index.js b/gather/src/index.js index 79ea7a8..32bbb84 100644 --- a/gather/src/index.js +++ b/gather/src/index.js @@ -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 }, + () => {} + ) } } })()