mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-24 18:32:41 +00:00
Change findOneAndUpdate to FindOne and Save
Setting an object property to `undefined` should tell Mongoose to remove that property (for example, remove the googleId from a brew). That doesn't seem to work with `findOneAndUpdate` however; the `undefined` property remains after the update. Switching back to `save()` to make this work again.
This commit is contained in:
@@ -247,9 +247,10 @@ const updateBrew = async (req, res)=>{
|
||||
brew = saved?.toObject();
|
||||
} else {
|
||||
// if the brew does have a stub id, update it using the stub id as the key.
|
||||
saved = await HomebrewModel.findOneAndUpdate({ _id: brew._id }, brew, {
|
||||
returnOriginal : false
|
||||
}).catch(saveError);
|
||||
brew = _.assign(await HomebrewModel.findOne({ _id: brew._id }), brew);
|
||||
saved = await brew.save()
|
||||
.catch(saveError);
|
||||
});
|
||||
}
|
||||
if(!saved) return;
|
||||
// Call and wait for afterSave to complete
|
||||
|
||||
Reference in New Issue
Block a user