Well, I am supposed to create a ‘Person’ model from a mongoose schema.
The code seems wrong for some reason, maybe I am missing something, I tried changing names and the case already.
Also please try to explain your solution as well.
Below is my code, thank you in advance!
Your code so far
const mongoose = require('mongoose');
var Schema = mongoose.Schema
var personSchema = new Schema({
name: {
type: String,
required: true
},
age: Number,
favouriteFoods: [String],
email: {
type: String,
unique: true
}
})
var Person = mongoose.model('Person', personSchema);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36.
Well I figured that creating an instance from the model I created was the problem, I was trying many different ways to fix it. You can amend the code if you want it’s fine as long as I’ll understand what is going on
Nope, i think there’s a problem beyond me this time, I even commented out every thing and left
var mongoose = require(‘mongoose’);
var Schema = mongoose.schema;
personSchema = new Schema ({
name: {
type: String,
required: true
},
age: number,
favoriteFood: [String]
});
var Person = mongoose.model(‘Person’, personSchema);
then at the bottom I commented out other exports and left
exports.PersonModel = Person;
This should be working but it’s not, it still says “Creating an instance from a mongoose schema should succeed” on @freeCodeCamp.
I even saw someone on youtube who did this challenge the same way I did and it passed on his side but it fails on my side. I created my own instances on Glitch, they passed. I recreated this project locally on VS Code, used Postman to make a POST request and it worked(locally) so I don’t know really.
Guys I finally found a solution, the problem was with Glitch, so I moved to repl.it, another online editor, I found out somewhere in the forum that glitch does this sometimes. Thank you for your help.