Puedo actualizar la cantidad de artículos en MongoDB pero no puedo actualizar la nueva cantidad con la cantidad anterior. como si tuviera 5 $ pero quiero actualizar como ( 5 + 8 = $ 13) y (5-2 = $ 3). cuando hago clic en el botón de aumento, el valor cambiará.
// datos mongoDB
{ _id : 626c4f18fffe01027aa8c1be, quantity : "1" } const Update = () => { const { updateId } = useParams(); const [carInfo] = useCarDetails(updateId); // [carInfo] get data by using specific id const addQuantity = (event) => { // eventhandler event.preventDefault(); const quantity = event.target.number.value; const updateCar = { quantity }; console.log(updateCar); fetch(`http://localhost:5000/Cars/${updateId}`, { method: "PUT", headers: { "Content-Type": "application/json", }, body: JSON.stringify(updateCar), }) .then((response) => response.json()) .then((data) => { console.log("Success:", data); alert("updateCar added successfully"); event.target.reset(); }); }; }// Este es el método put de Mongodb
app.put("/Cars/:id", async (req, res) => { const id = req.params.id; const newCars = req.body; const filter = { _id: ObjectId(id) }; const options = { upsert: true }; const updateCar = { $set: { quantity: newCars.quantity, }, }; const result = await carCollection.updateOne(filter, updateCar, options); res.send(result); });