From 21b30c53dbb76ac303b191046c3fb70dced34898 Mon Sep 17 00:00:00 2001 From: AbhishekPanta8 Date: Fri, 17 Mar 2023 12:17:21 +0530 Subject: [PATCH] Fixed uncaught dup key with caracal @ develop #140 --- service/database/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/service/database/index.js b/service/database/index.js index 81e9a97..c469433 100644 --- a/service/database/index.js +++ b/service/database/index.js @@ -87,7 +87,10 @@ class Mongo { const res = await collection.insertMany(data); return res; } catch (e) { - if (silent) { + if (e.code === 11000) { + console.warn(`Duplicate key error in collection '${collectionName}': ${e.keyValue}`); + return; + } else if (silent) { console.warn('insert into ' + collectionName + ' did not occur, continuing because silent set') } else { console.error(e);