Tell us what’s happening:
My createAndSavePerson function won’t work. I keep getting
(node:18723) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
11:24 PM
(node:18723) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Your code so far
var Person = mongoose.model(‘Person’, personSchema)
var Person = mongoose.model(‘Person’, personSchema)
var createAndSavePerson = function(done) {
var johnRon = new Person({name: “John Ron”, age: 84, favoriteFoods: [‘Pizza’, ‘Burger’, ‘Ice Cream’]});
johnRon.save(function(err, data){
if (err){
return done(err);
}
done(null, data);
});
};
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36
.
Challenge: MongoDB and Mongoose - Create and Save a Record of a Model
Link to the challenge:
https://www.freecodecamp.org/learn/apis-and-microservices/mongodb-and-mongoose/create-and-save-a-record-of-a-model