This is my code
and this is the challange
Don’t use new mongoose.Schema
Use new Schema
Hi,
The challenge is asking you to specify a default value, like this:
const schema = new Schema( {
name: {
type: String,
required: true
},
age: Number,
favoriteFoods: {
type: [ String ],
default: 'Pizza, of course'
}
} );
mongoose.Schema should be required unless you save mongoose.Schema into a new variable named Schema, like this: const Schema = mongoose.Schema
. Otherwise Node won’t know what Schema is, right?
Actually you are right,
I assumed he defined mongoose.Schema in to Schema already. Good catch, therefore @seinfeld70 you can ignore what I said above.
I always make a copy to a new variable too. It looks cleaner to me
const Schema = mongoose.Schema;
var Person = new Schema({
name: {type: String, required: true},
age: {type: Number, default: 23},
favoriteFoods: {type: [String], default: 'Pizza'}
});
This code is still giving me incorrect Person model.
Please help.
I have the same problem.
This is my code:
const Schema = mongoose.Schema;
const Person = new Schema({
name: {
type: String,
required: true,
default: ‘Cesar’
},
age: {
type: Number,
default: 23
},
favoriteFoods: {
type: [String],
default: ‘Pizza’
}
});
And the error is: Person Model is not correct
I dont know what can I do.
Help me please. Thank you.
Now I found the solution. You need to do That.
const Schema = mongoose.Schema;
const personSchema = new Schema({
name: {
type: String,
required: true
},
age: {
type: Number
},
favoriteFoods: {
type: [String],
default: ‘Pizza’
}
});
var Person = mongoose.model(‘Person’, personSchema);
This works.