'Node js multer send image without update

friends, I am developing a project with node js, I have a form in my hand, in this form I send pictures and texts to the database (MongoDB), there are no problems with them, including uploading images and updating and sending images.

But the user may want to update and send only the articles, and in this case, he may not want to update the picture. I think about this, I want to send the data to the database without updating the picture, I actually did this, but this time I cannot update the picture while it is in the update process, how can I solve this problem? can you help?

Thank you from now.

The code block I did the update process is as follows

const medicine = await Medicine.findOne({ _id: req.params.id });
    medicine.name = req.body.name;
    medicine.price = req.body.price;
    medicine.medicineType = req.body.medicineType;
    medicine.description = req.body.description;

if (req.body.image) {

  medicine.image = '/uploads/' + req.file.filename;

} else if (!req.body.image) {
  
}else{

}

console.log(req.body);
medicine.save();


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source