FindOneAndRemove()

What is your hint or solution suggestion?
FindOneAndRemove() is similar with FindByIdAndRemove() - it take the person id as filter as the first argument , and a callback function at the second argument.

Solution: const removeById = (personId, done) => {
// _id is automatically generate and unique for each of the object store in MongoDB
Person.findOneAndRemove({ _id: personId } , function(err,result){
if(err) console.error(err);
done(null , result);
})
};

Challenge: Delete One Document Using model.findByIdAndRemove

Link to the challenge:

https://www.freecodecamp.org/learn/apis-and-microservices/mongodb-and-mongoose/delete-one-document-using-model.findbyidandremove

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.