I’m working through the API & Microservices course and have got stuck trying to implement Person.findOneAndUpdate().
Whenever I run my code I get an error saying the test has timed out, and I’m not sure what I’ve done wrong.
The error:
// running tests
findOneAndUpdate an item should succeed (Test timed out)
// tests completed
My code so far:
I’ve been trying to follow the syntax suggested by the course, with all these nested callbacks and whatnot, and it’s worked completely fine up to this lesson. Chances are I’ve just made a silly mistake but I would really appreciate someone helping me out
var findAndUpdate = function(personName, done) {
var ageToSet = 20;
Person.findOneAndUpdate(
{name: personName},
function(err, person) {
if (err) return console.log(err);
person.age = ageToSet;
person.save((err, data) => {
if (err) return console.log(err);
done(null, person);
})
},
{new: true}
);
};
My browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:74.0) Gecko/20100101 Firefox/74.0
.
Challenge: MongoDB and Mongoose - Perform New Updates on a Document Using model.findOneAndUpdate()
Link to the challenge: