It seems there is a bug in the testing. It updates and returns in updated record in the console. However, it does not pass teh test. can anyone tell me what is wrong please?
var findAndUpdate = function(personName, done) {
var ageToSet = 20;
//console.log("person name : ", personName);
Person.findOneAndUpdate(
{"name": personName},
{$set: {"age":ageToSet}},{returnNewDocument : true},
function(err, doc){
if(err){
console.log("Something wrong when updating record!");
}
console.log(doc);
})};
The console returns
POST
person name is : Dorian Gray
{ favoriteFoods: [ 'unknown' ],
_id: 5b370e3cb62c7d06e2553240,
name: 'Dorian Gray',
age: 20,
I removed the $set from line 6 and it seems to still work. And I removed the return statements on lines 10 and 12 (just to match how my other answers look). Also it no longer returns data if thereās an error on line 10.
In order to get rid of a warning, include the key useFindAndModify in the options-document sent to findOneAndUpdate like this (presumable this is equivalent to what @codedbycarlos wrote above.
Thank you for your reply here! I find that these challenges are not well written. Iām really struggling with these Mongoose challenges, but itās not a useful struggle. Iām struggling because I donāt have enough direction.