Hi all,
My collection called ‘people’ was successfully created in MongoDB database, but there is no data in the document. I have passed the challenge up the Use model.find() to Search Your Database section, but I need to know why my data/records are not being created before I proceed with other challenges.
I have to even comment out 'pers.remove() in the server.js file, thinking that the line of code may be what is ‘deleting’ my data, but the data record still does not show. See my code below:
//Create a Schema
let Schema = mongoose.Schema;
let personSchema = new Schema({
name: {
type: String,
required: true
},
age: {
type: Number
},
favoriteFoods: [String]
});
//compile a model from the schema to create a collection
const Person = mongoose.model('Person', personSchema);
//create and save a record of a Person model
const createAndSavePerson = (done) => {
const Person = new Person({
name: 'Bessie',
age: 17,
favoriteFoods: ['cereal', 'snacks', 'pasta']
});
Person.save((err, data) => {
if(err){
console.log (err)
} else {
done(null, data)
}
});
};
Again, the above code has passed the challenge, but there is no data record in the document in the database. This is my worry!