From d3d6712ff826a1ee67a376bf239f880ebae5ae28 Mon Sep 17 00:00:00 2001 From: Aydan Pirani Date: Sun, 14 Apr 2024 17:09:35 -0500 Subject: [PATCH] Ensure that emails are unique --- src/services/subscription/subscription-router.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/subscription/subscription-router.ts b/src/services/subscription/subscription-router.ts index e8b7a5f..55d6c69 100644 --- a/src/services/subscription/subscription-router.ts +++ b/src/services/subscription/subscription-router.ts @@ -14,7 +14,7 @@ subscriptionRouter.post("/", async (req, res, next) => { // Upsert the user info into the corresponding Subscription collection await Database.SUBSCRIPTIONS.findOneAndUpdate( { mailingList: subscriptionData.mailingList }, - { $push: { subscriptions: subscriptionData.email } }, + { addToSet: { subscriptions: subscriptionData.email } }, { upsert: true, new: true } ); return res.status(StatusCodes.CREATED).json(subscriptionData);