MongoDB and Mongoose - Delete One Document Using model.findByIdAndRemove

MongoDB and Mongoose - Delete One Document Using model.findByIdAndRemove
0

#1

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.


#2

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.


#3

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


#4

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…


#5

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


#6

No problem!:grin:

It just came into my mind,but thanks.