From 5007e48c8546d8138092039bf3cecc0b9904a407 Mon Sep 17 00:00:00 2001 From: Factiven Date: Thu, 13 Apr 2023 22:14:50 +0700 Subject: Update 4th --- pages/api/update-user.js | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'pages/api/update-user.js') diff --git a/pages/api/update-user.js b/pages/api/update-user.js index 210d70f..67c80d0 100644 --- a/pages/api/update-user.js +++ b/pages/api/update-user.js @@ -9,6 +9,16 @@ export default async function handler(req, res) { const { name, newData } = req.body; // id is the user ID and newData is the new data you want to set try { + const existingData = await collection.findOne({ + name: name, + "recentWatch.id": newData.recentWatch.id, + }); + + if (existingData) { + res.status(200).json({ message: "Data already exists" }); + return; + } + const result = await collection.updateOne( { name: name }, { $addToSet: newData } -- cgit v1.2.3