Currently working through the MongoDB and Mongoose section on FreeCodeCamp.
The challenge involves creating a document instance using the Person constructor previously built. The object passed to the constructor should have fields for name, age, and favoriteFoods that comply with the types in the Person Schema. Then, call the document.save() method on the returned document instance and provide a callback following the Node convention.
I've set up the person schema and constructor, but I'm unsure about what's missing and how to properly put it all together to solve the problem. Can anyone offer clarification?
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*/);
};