MongoDB and Mongoose - Create a Model Error: The 2nd parameter to `mongoose.model()` should be a schema or a POJO

Tell us what’s happening:
Hello There i am stuck here, i keep getting this error when i use the code below

Your code so far


// <Your code here >
const personSchema = mongoose.Schema;
var Person = new personSchema({
  name: {type: String, required: true},
  age: Number,
  favoriteFoods: [String]
}); 

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

I get no error when i use this code but it wont pass the challenge.

const personSchema = mongoose.Schema;
var Person = new personSchema({
  name: {type: String, required: true},
  age: Number,
  favoriteFoods: [String]
}); 

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

my error is

    throw new Error('The 2nd parameter to `mongoose.model()` should be a ' +

    ^

Error: The 2nd parameter to `mongoose.model()` should be a schema or a POJO

Thank you for taking your time to help. cheers
Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:75.0) Gecko/20100101 Firefox/75.0.

Challenge: MongoDB and Mongoose

Link to the challenge:

Welcome, devnechi.

Think about what you are declaring here:

const personSchema = mongoose.Schema;
var Person = new personSchema({
  name: {type: String, required: true},
  age: Number,
  favoriteFoods: [String]
}); 

 var Person = mongoose.model('person', personSchema);
  1. personSchema is the Schema object of Mongoose.
  2. Person is a new instance of that schema.
  3. Person is now a model based on the Schema object.

Can you see why this does not make sense?

thank you for getting back to me.

I am guessing

Person

model is the culprit here, so i tried


// <Your code here >
const personSchema = mongoose.Schema;
var Person = new personSchema({
  name: {type: String, required: true},
  age: Number,
  favoriteFoods: [String]
}); 

 var newPerson = mongoose.model('person', personSchema);

so i used a new variable for the model called

newPerson

I still get the same error.
Am I missing something here. please help

Thanks guys, I figured it out.
rookie mistake

this code does work.

// <Your code here >
const personSchema = mongoose.Schema;
var Person = new personSchema({
  name: {type: String, required: true},
  age: Number,
  favoriteFoods: [String]
}); 

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

thanks for all the help