Hi, I am looking for help with the failing test case below for exercise at https://www.freecodecamp.org/learn/back-end-development-and-apis/mongodb-and-mongoose/create-a-model
Failing test case ----> Creating an instance from a mongoose schema should succeed. <—
This is pre-included in ther server.js file setup by freecodecamp project -
const enableCORS = function (req, res, next) {
if (!process.env.DISABLE_XORIGIN) {
const allowedOrigins = [“https://www.freecodecamp.org”];
const origin = req.headers.origin;
if (!process.env.XORIGIN_RESTRICT || allowedOrigins.indexOf(origin) > -1) {
console.log(req.method);
res.set({
“Access-Control-Allow-Origin”: origin,
“Access-Control-Allow-Methods”: “GET, POST, OPTIONS”,
“Access-Control-Allow-Headers”:
“Origin, X-Requested-With, Content-Type, Accept”,
});
}
}
next();
};
My solution adds the following:
mongoose.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true
});
const personSchema = new mongoose.Schema({
name: {
type: String,
required: true
},
age: Number
})
const Person = mongoose.model(‘Person’, personSchema);