Create a Model Error: "Creating an instance from a mongoose schema should succeed"

Tell us what’s happening:
Trying to complete some back end challenges and for whatever reason my code is not working even though it should. Like, it should. The previous challenge clears my code so I know it’s not that.

I’ve looked at the solution and copied it word for word and still it won’t let me pass.

Your code so far

const Schema = mongoose.Schema;

const personSchema = new Schema({

     name: { type: String, required: true, default: "Person" },

     age: { type: Number, required: false, default: 0 },

     location: { type: String, required: true, default: "Nowhere" },

     favoriteFoods: {

          type: Array(String),

          required: false,

          default: ["Cheese", "Among other things"]

  }

});

const Person = mongoose.model("Person", personSchema);

Challenge: Create a Model

Link to the challenge:

Welcome, Atrocity.

Just to mention it: My understanding of favoriteFoods : array of strings (*) is favoriteFoods is an array of strings which is optional. So, the default case should not be there.

Regarding your code not passing, it is difficult to say, without seeing your project. However, the best way for you to find out, is by ensuring your project is behaving the way it should:

  1. If you are using Glitch, ensure you can view the live app, and the server is running.
  2. Ensure there are not obvious errors in the console.
  3. After submitting your project on freecodecamp.org/learn..., open the browser console, and look for any CORS related errors.

Hope this helps

1 Like

Thank you so much! LOL sometimes I can’t believe the errors I make but thank you thank you thank you!