Mongoose findOneAndUpdate won't update my database
Refering the doc, https://mongoosejs.com/docs/tutorials/findoneandupdate.htmlfirst parameter of findOneAndUpdate
should be a filter object, not the id directly.
So please try Partner.findOneAndUpdate({'_id': id},....
This is a syntax for findOneAndUpdate as per the docs:
var query = { name: 'borne' };Model.findOneAndUpdate(query, { name: 'jason bourne' }, options, callback)
Change db query to this:
let query = {_id: id };let dataToUpdate= { "fullname": fullname, "email": email, "phones": phones, "shops":shops, "company": company }let options = {useFindAndModify: false} // useFindAndModify set to false at query level// options = {useFindAndModify: false,new:true} if you want updated docs in return Partner.findOneAndUpdate(query,dataToUpdate,options,(err, document) => { if (err) return err; //console.log(document); res.send({ document }); } )
To set Deprecation Warnings on or off at mongoose level use option
mongoose.set('useFindAndModify', false)
Read more here:
You can also use findByIdAndUpdate
method:
Model.findByIdAndUpdate(id, update, options, callback)
You can enable promises to make code more readable and testable:https://mongoosejs.com/docs/promises.html