Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongodb updateOne method is not working with mongoose 5.4.10

I am trying to update record of mongodb using updateOne method but it's not working.

async function updateCourse(id) {
   const result = await  Course.updateOne({_id : id }, { name: 'Abc'}, 
         function(err, res) {});
   console.log(result);
}

anyone please suggest possible solution to fix this issue.

Thanks

like image 726
Ankit Avatar asked Jan 21 '26 13:01

Ankit


1 Answers

try this code

const test = async function updateCourse(id) {
  const result = await Course.updateOne({ _id: id }, { name: "Abc" })
  console.log(result);
};

If you using async await, don't use callback again

I hope this can help you. Thank you

like image 183
Wicak Avatar answered Jan 23 '26 09:01

Wicak