I am currently on the MongoDB and Mongoose section of FreeCodeCamp.
The exercise requires the user to create a document instance using the Person constructor you build before. Pass to the constructor an object having the fields name, age, and favoriteFoods. Their types must be conformant to the ones in the Person Schema. Then call the method document.save() on the returned document instance. Pass to it a callback using the Node convention.
I have created the person schema and constructor but I am not too sure about what is still missing and how to piece it all together to implement the solution. Can someone help clarify?
var mongoose = require("mongoose");
mongoose.connect(process.env.MONGO_URI);
var Schema = mongoose.Schema;
var personSchema = new Schema({
name: {
type: String,
required: true
},
age: Number,
favoriteFoods: [String]
});
var Person = mongoose.model('Person', personSchema);
var joe = new Person({
name: "Joe",
age: 24,
favoriteFoods: ['Apple', 'Banana']
});
joe.save(function(err, persons) {
if(err){
console.log("Failed");
} else {
console.log("Saved Successful");
console.log(persons);
}
});
var createAndSavePerson = function(done) {
done(null /*, data*/);
};