MongoDB and Mongoose - Delete One Document Using model.findByIdAndRemove

Description: “Delete one person by her _id. You should use one of the methods findByIdAndRemove() or findOneAndRemove(). They are like the previous update methods. They pass the removed document to the cb. As usual, use the function argument personId as search key.”

Please help here, Not really sure how to pass this challenge, I feel like, I’ve tried many combinations already.

Here’s the solution,buddy:
var removeById = function(personId, done) {
Model.findByIdAndRemove(personId, (err, data) => err ? done(err) : done(null, data));
};
Did you realised that the only thing I change was findById and personId?
Good luck on your other challenges.

7 Likes

Thanks for the reply. Any idea why it says “Model.findByIdAndRemove is not a function”?

Maybe the

Model.findByIdAndRemove

Should be:
Person.findByIdAndRemove???
I don’t know the real solution of this question either,but I think that can happen…

3 Likes

Has anyone told you, you are the best! Thank you, it worked just a small mistake. Thanks a ton!

No problem!:grin:

It just came into my mind,but thanks.