delete all images by using single user id
// User delete all images by using user id
const deleteAllImagesByUserId = async (req, res) => {
try {
const user = await User.findByIdAndUpdate(
req.params.userId,
{
$pull: { images: {} },
},
{ new: true }
);
console.log("zzzu: ", user);
if (!user) {
return res.status(400).send("User not found");
}
await Imageup.deleteMany({user: req.params.userId},
function(err, result) {
if (err) {
res.send(err);
} else {
res.send(result);
}
}
)
res.status(200).json({ message: "Successfully all images are deleted!" });
} catch (err) {
res.status(500).send("Something went abnormally!");
}
};