Sunday 18 June 2023

How to update data by id in mongodb and nodejs REST Api

 Today i will share again about imformation "How to update data by id in mongodb and nodejs REST Api"

Ok lets check it out following codes :

exports.updateDataActivityById = async function(req, res)
{
    let id = {"_id": req.body.id};
    let editValue = {$set: {activity: req.body.activity, description: req.body.description }};
    dy.updateOne(id, editValue)
    .then((docs)=>{
     
        res.json(docs);
    })
    .catch((err)=>{
        console.log(err);
        res.status(401).json({ message: 'Something Wrong' });
    });
};


dy.updateOne(id, editValue)

= This is main script to update data by value id.

Ok just that is information I want to share . Hope this information can helping you. Thanks


No comments:

Post a Comment