0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-08 03:12:40 +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:
Trevor Buckner
2022-12-12 09:59:04 -05:00
parent 263471bcbb
commit 326c28a11d

View File

@@ -247,9 +247,10 @@ const updateBrew = async (req, res)=>{
brew = saved?.toObject(); brew = saved?.toObject();
} else { } else {
// if the brew does have a stub id, update it using the stub id as the key. // 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, { brew = _.assign(await HomebrewModel.findOne({ _id: brew._id }), brew);
returnOriginal : false saved = await brew.save()
}).catch(saveError); .catch(saveError);
});
} }
if(!saved) return; if(!saved) return;
// Call and wait for afterSave to complete // Call and wait for afterSave to complete