From 4b98c1ac895c41acea5022a3cd554f82b537bb74 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Fri, 17 Feb 2023 11:26:11 +1300 Subject: [PATCH] Add markModified to fix authors array in DB --- server/homebrew.api.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/homebrew.api.js b/server/homebrew.api.js index f531bdcf9..228a08128 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -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 };