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

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


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 // String


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


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 (*)


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:


const mongoose = require(‘mongoose’);

/** 2) Create a ‘Person’ Model */
const Schema = mongoose.Schema;
const personSchema = new Schema({
age: Number,

const Person = mongoose.model(‘Person’, personSchema);

please tell me somebody what is wrong with my code.


Here is my code, it work.

var Schema = mongoose.Schema;

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

var Person = mongoose.model(“Person”, personSchema);


Aaaaah! The real issue is in the order of the variables you declare. I placed Person below personSchema and the damn thing worked.