Tell us what’s happening:
Hi there , I’m trying to pass this test lately but I couldn’t understand the concept of models and schemas I visited the hint link and I have few question about the solution
const mongoose = require('mongoose');
mongoose.connect(process.env.MONGO_URI);
/** 2) Create a 'Person' Model */
var personSchema = new mongoose.Schema({
name: String,
age: Number,
favoriteFoods: [String]
});
/** 3) Create and Save a Person */
var Person = mongoose.model('Person', personSchema);
var createAndSavePerson = function(done) {
var janeFonda = new Person({name: "Jane Fonda", age: 84, favoriteFoods: ["eggs", "fish", "fresh fruit"]});
janeFonda.save(function(err, data) {
if (err) return console.error(err);
done(null, data)
});
};
- What does this line do exactly
var Person = mongoose.model('Person', personSchema)
; - Whats the diffrence beween Schema and Model ?
- Why we wrote the word Person in capital letter ?
- What the word “done” in
function(done)
do ? - what’s the exact job of the last line
done(null, data)
? - Finely Im getting this message in the consol after trying to run my code :
Your App Link
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36
Challenge: Create and Save a Record of a Model
Link to the challenge: