Getting this error on trying to update....mongoose is throwing this error on using the code below....have tried using const project = {...} instead of new Product({...}) but no luck.
router.put("/:id", multer({storage: storage}).single("image") , (req, res, next) => {
let imagePath = req.body.imagePath;
if (req.file) {
const url = req.protocol + "://" + req.get("host");
imagePath = url + "/images/" + req.file.filename
}
const product = new Product(
{
_id: req.body.id,
title: req.body.title,
cost: req.body.cost,
description: req.body.description,
imagePath: imagePath
}
) ;
console.log(product)
Product.updateOne({_id: req.params.id}, product)
.then(result => {
console.log(result);
res.status(200).json({ message: "Update Successful !!"});
});
});