I am trying to push an element to an array in mongoose. I am doing it with update and $push. But it is not updating it in the database. This is my code. routes.js:
We can do like that
Model.findOneAndUpdate({"_id":req.body.id},{
"$push": {"resources": req.body.resources}
},{new: true, safe: true, upsert: true }).then((result) => {
return res.status(201).json({
status: "Success",
message: "Resources Are Created Successfully",
data: result
});
}).catch((error) => {
return res.status(500).json({
status: "Failed",
message: "Database Error",
data: error
});
});`