Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

364
Views
Having a problem in deleting items in mongoos using the findOneByIdAndRemove() function

I'm solving a FREECODECAMP challenge, to pass this challenge I need to remove a person by his ID.

the problem is that I tried the suggested function like findByIdAndRemove() and I still can not pass the challenge and the console shows this err :

(node:9144) [MONGODB DRIVER] Warning: collection.remove is deprecated. Use deleteOne, deleteMany, or bulkWrite instead.
(Use `node --trace-warnings ...` to show where the warning was created)
{
  _id: new ObjectId("61f2637736f4aea8452a638e"),
  name: 'Jason Bourne',
  age: 36,
  favFood: [],
  __v: 0
}
{
  _id: new ObjectId("61f2637736f4aea8452a638e"),
  name: 'Jason Bourne',
  age: 36,
  favFood: [],
  __v: 0,
  count: 0
}

this is my code so far :

const removeById = function(personID, done) {
  Person.findByIdAndRemove(personID, (err, IDR) => {
    if(err) return console.log(err);
    done(null, IDR);
  });
};

Thank you in advance <3

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

FindOneAndRemove is deprecated. Please use deleteOne

const user_id = "user_id_to_delete";
await collection.deleteOne({_id: user_id});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!