I'm having trouble performing updates Using model.findOneAndUpdate()

I'm having trouble performing updates Using model.findOneAndUpdate()
0

#1

I’m having trouble passing the test. I keep getting:
// running tests
item.favoriteFoods is not what expected
// tests completed

Link to FCC challenge: https://learn.freecodecamp.org/apis-and-microservices/mongodb-and-mongoose/perform-new-updates-on-a-document-using-model-findoneandupdate/

Here’s my code:

var ageToSet = 20;

Person.findOneAndUpdate(
 {name: personName},
 {$set: {age: ageToSet}},
 {new: true},
 function(err, data) {
   if (err) {return done(err);}
   return done(null, data);
 }
);
};```

#2

You don’t need to return done in here. Try removing ‘return’ keyword.


#3

I tried it but i’m still getting the same error


#4

Also try removing done from here.

I also hope you have

var findAndUpdate = function(personName, done) {

before your var ageToSet = 20;


#5

yes I removed return from both done(null, data) and done(err), and I have var findAndUpdate = function(personName, done). I don’t know what i’m doing wrong


#6

I am not so sure why yours is not passing.

Here is my code that passes but doesn’t look much different from yours. Maybe you can spot a difference.

Summary
var findAndUpdate = function(personName, done) {
  var ageToSet = 20;

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

#7

I’m just going to move on to the next challenge and skip this one. Thank you :slight_smile: