Having some trouble getting this code to work properly where I use $inc to increase the number of likes and $push to add the userId to the usersLiked array:
Sauce.updateOne(
{ _id: req.params.id },
{
...sauceObject,
likes: req.body.like,
dislikes: req.body.like,
usersLiked: req.body.userId,
usersDisliked: req.body.userId,
}
)
.then(() => res.status(200).json({ message: "Sauce liked !" }))
.catch((error) => res.status(400).json({ error }));
I attempted this approach, but encountered an error:
db.Sauce.update(
{ _id: req.params.id },
{
$push: { usersLiked: req.body.userId },
$inc: { likes: 1 },
}
.then(() => res.status(200).json({ message: "Sauce liked !" }))
.catch((error) => res.status(400).json({ error }))
);
Your assistance is greatly appreciated :D