I am having a problem also on “Create and Save a Record of a Model”:
Schema and Model:
const personSchema = new Schema({
name: { type: String, required: true },
age: Number,
birthDate: { type: Date, required: true },
favoriteFoods: [String],
creationTimestamp: { type: Date, required: true, default: Date.now }
})
let Person = mongoose.model('Person', personSchema)
When I save the document this way, freeCodeCamp test is successful, but the document is not saved in the database (mLab):
var createAndSavePerson = function(done) {
let person = new Person({
name: 'João Neves',
age: 21,
birthDate: '1995/07/11',
favoriteFoods: ['Lasagna', 'Pasta']
})
person.save((err, data) => {
if (err)
return done(err)
console.log(data)
done(null, data)
})
}
But when I do it this way, freeCodeCamp’s test fails but the document is saved in the database:
var createAndSavePerson = function(done) {
let person = new Person({
name: 'João Neves',
age: 21,
birthDate: '1995/07/11',
favoriteFoods: ['Lasagna', 'Pasta']
})
person.save((err, data) => {
if (err)
throw err
console.log(data)
})
}
I’m also getting this warning on the console (?):
"(node:11040) DeprecationWarning: Mongoose: mpromise (mongoose’s default promise library) is deprecated, plug in your own promise library instead: http://mongoosejs.com/docs/promises.html"