0

I tried to use this method in mongoose, Model.findByIdAndUpdate(), but the console shows it as deprecated.

I know that's a disable warning.

My question is, what is the correct method to make this petition?

User.findByIdAndUpdate(data.id,{$set:user},{new: true},(errUpdate, result)=>{
            if(errUpdate){
                console.log("error",errUpdate);
            }
            if(data){
                console.log("result", result);

            }
        })
ChrisM
  • 505
  • 6
  • 18
  • Possible duplicate of [Mongoose findByIdAndUpdate successfully updates document but ruturns error](https://stackoverflow.com/questions/49198856/mongoose-findbyidandupdate-successfully-updates-document-but-ruturns-error) – Kavitha Karunakaran Sep 09 '19 at 02:06

1 Answers1

0

did you tried mongoose findOneAndUpdate()

The findOneAndUpdate() function in Mongoose has a wide variety of use cases. You should use save() to update documents where possible, but there are some cases where you need to use findOneAndUpdate()

Read more at How to Use findOneAndUpdate() in Mongoose

User.findOneAndUpdate(data.id,{$set:user},{new: true},(errUpdate, result)=>{
            if(errUpdate){
                console.log("error",errUpdate);
            }
            if(data){
                console.log("result", result);

            }
        })
Bivin Vinod
  • 2,210
  • 1
  • 12
  • 15