Remove or Delete One Document Using model.findByIdAndRemove or model.findOneAndRemove

What is your hint or solution suggestion?

  • To delete a user’s _id you need to use Model.findByIdAndRemove. However, there are other options which such as; Model.findOneAndRemove or Model.findOneAndDelete.

  • Also, use the function argument personId as search key.

  • Solution: const removeById = (personId, done) => { Person.findByIdAndRemove(personId, (err, data) => { if (err) return console.log(err); done(null, data); }); };

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