findOneAndUpdate not working in challenge

I had been trying to make my code pass the test in the below challenge but it still didn’t pass. I tried doing multiple things which include adding $set in the update statement, adding useFindAndModify: false in the options, replacing ageToSet with 20 in the update statement and using the done() callback in case an error occurs. This is my latest code that didn’t pass the test:

const findAndUpdate = (personName, done) => {
  const ageToSet = 20;

  Person.findOneAndUpdate({name: personName}, {age: 20}, {new: true} , (err, data) => {
    if (err) {
      return done(err);
    done(null, data);

I also tried the solution to the challenge which also didn’t work. Was anyone able to make it work?

Challenge: Perform New Updates on a Document Using model.findOneAndUpdate()

Link to the challenge:

1 Like

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