Create and save a record of model

What is missing in the code?

var createAndSavePerson = function(done) {
  var person = new Person({
    name: 'Ishaan',
    age: 20,
    favoriteFoods: ['Bread','Cheese']
  });
  person.save(function(err, data) {
        if (err) return console.error(err);
    done(null, data);
  });
};

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36.

Challenge: undefined

Link to the challenge:
https://www.freecodecamp.org/learn/apis-and-microservices/mongodb-and-mongoose/create-and-save-a-record-of-a-model

try favouriteFoods instead. Might be a typo.

http://pythontutor.com/javascript.html#mode=display
i think that tool might help you find the errors
also do make sure to proper close things with the ;

1 Like

Did not get you sir.
Can you please elaborate?

What if you return done(err) instead of console.error(err)

I tried it and it worked
, thanks.