# FindOneAndRemove()

**URL:** <https://forum.freecodecamp.org/t/findoneandremove/462934>\
**Category:** freeCodeCamp Contributors\
**Tags:** contributing\
**Created:** [June 1, 2021, 12:39pm UTC](https://forum.freecodecamp.org/t/findoneandremove/462934 "2021-06-01T12:39:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![krezatulpod](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/krezatulpod/32/208946_2.png) [@krezatulpod](https://forum.freecodecamp.org/u/krezatulpod)\
**Post date:** [June 1, 2021, 12:39pm UTC](https://forum.freecodecamp.org/t/findoneandremove/462934/1 "2021-06-01T12:39:15Z")

</div>

**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](https://www.freecodecamp.org/learn/apis-and-microservices/mongodb-and-mongoose/delete-one-document-using-model.findbyidandremove)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [December 1, 2021, 12:40am UTC](https://forum.freecodecamp.org/t/findoneandremove/462934/2 "2021-12-01T00:40:09Z")

</div>

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