freeCodeCamp Challenge Guide: MongoDB and Mongoose - Delete One Document Using model.findByIdAndRemove

Hint

Use id and callback arguments in both findOneAndRemove and findByIdAndRemove methods

Solutions

Solution 1
const removeById = (personId, done) => {

  Person.findOneAndRemove({_id: personId}, (err, removedPerson) => {
    if(err) return console.log(err);
    done(null, removedPerson);
  })
};
Solution 2
const removeById = (personId, done) => {

  Person.findByIdAndRemove(personId, (err, removedPerson) => {
    if(err) return console.log(err);
    done(null, removedPerson);
  })
};