Sunday, May 23, 2021

Remove a document using mongoose

async function removeCourse(id){

 const result = await Course.deleteOne({_id: id});
 console.log(result);
}

removeCourse("<id_of_a_course>");

//Use deleteMany instead of deleteOne if multiple matches are there in query string.

//To retrieve course object instead of result code.
//const course = await Course.findByIdAndRemove(id);

No comments:

Post a Comment