MongoDB and Mongoose - Perform Classic Updates by Running Find, Edit, then Save

Hello, I think my code is correct, I’ve been stuck on this for a while.
The error on the console says TypeError: Cannot read properties of undefined (reading ‘push’)

I don’t know what that means

Your project link(s)

solution: boilerplate-mongomongoose - Node.js Repl - Replit

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36 Edg/105.0.1343.42

Challenge: MongoDB and Mongoose - Perform Classic Updates by Running Find, Edit, then Save

Link to the challenge:

Hello!

Your code is not correct.

Read this:

Modify the findEditThenSave function to find a person by _id

But your code has this:

const findEditThenSave = (personId, done) => {
  const foodToAdd = "hamburger";
  Person.update(personId, function(err, pers){

See the problem?

After fixing that, the following task is:

Add "hamburger" to the list of the person’s favoriteFoods (you can use Array.push())

Which in your code is not correct either. The Person variable is an instance of a mongoose Model, which doesn’t have access to the favoriteFoods properties, only an instance of a Document would have access to that property (and others). This means that you should be using the data returned by the database (a Document) instead of the Model.

Hope it helps :slight_smile:.