Add markModified to fix authors array in DB

This commit is contained in:
G.Ambatte committed 2023-02-17 11:26:11 +13:00
1 parent d9f5e9d635
commit 4b98c1ac89
1 file changed
+5
+5
View File
@@ -319,6 +319,11 @@ If you believe you should have access to this brew, ask the file owner to invite
}
// Otherwise, save the brew with updated author list
// markModified() is necessary to have Mongoose reduce the array length in the database
// Without it, starting with an array of ['A', 'B', 'C'] in the database:
// - when reduced to ['A', 'B'] will result in ['A', 'B', 'C'] saved in the database
// - when reduced to ['B', 'C'] will result in ['B', 'C', 'C'] saved in the database
brew.markModified('authors');
await brew.save()
.catch((err)=>{
throw { status: 500, message: err };