MongoDB and Mongoose - Create a Model (is it broke?)

MongoDB and Mongoose - Create a Model (is it broke?)
0.0 0

#1

On the above challenge, I just can’t get my code to work… database is connecting and all packages etc. are present.

I’ve copied and pasted solutions from two other similar topics and they don’t work either.

My code:

var personSchema = new Schema({
   name: {type: String, required: true},
   age: Number,
   favouriteFoods: [String]
});

var Person = mongoose.model('Person', personSchema);

My code generates the error:

“model.favoriteFoods” is not an Array

When debugging, I get:

console.log(typeof Person.age) // undefined
console.log(typeof Person.favouriteFoods) // undefined
console.log(typeof Person.name) // String

#2

Might be because FCC is looking for the American spelling of “favorite”


#3

The instructions tell you what to name the properties.

Create a person having this prototype :

  • Person Prototype -

name : string [required]

age : number

favoriteFoods : array of strings (*)


#4

Yep, that was the fix… I can’t tell you how much this one has been driving me crazy! Can’t believe I didn’t spot that one. Thanks so much! :blush: