hello i am encountering the following error after pushing the array ‘favoriteFoods’:
UnhandledPromiseRejectionWarning: VersionError: No matching document found for id “5de95a18c45e5b135b4d0070” version 0 modifiedPaths “favoriteFoods”
this occurs in the save method.
OJL
December 5, 2019, 8:16pm
2
@OJL use a update method instead? i tried to… but don’t pass in tests
OJL
December 5, 2019, 9:19pm
4
hello, any other suggestions? I’m really stuck in this …
2 Likes
I had the same issue as you xandeact and couldn’t figure out what was going on - I remixed your proj and used your code and it worked! I saw that you added the done callback in the save function, instead of after the save function. Fixed for me, thanks.
Before:
Person.findById(personId, function(err, p){
if (err) return console.error(err);
p.favoriteFoods.push(foodToAdd);
p.save();
done(null, p);
});
After:
Person.findById(personId, function(err, p){
if (err) return console.error(err);
p.favoriteFoods.push(foodToAdd);
p.save(function(err, p){
if (err) return console.error(err);
done(null, p);
});
});
2 Likes
You saved my life. I was trying many solutions for a few days but none of them worked.
It worked!
var findEditThenSave = function(personId, done) {
var foodToAdd = "hamburger";
Person.findById(personId, function(err, personFound) {
err ? console.error(err) : personFound;
personFound.favoriteFoods.push(foodToAdd);
personFound.markModified("edited-field");
personFound.save((err, personFound) => (err ? console.error(err) : done(null, personFound)));
});
};