From 254642be973a0ffb1cb744432d8a53b3e258dae6 Mon Sep 17 00:00:00 2001 From: Aleksandr Saitgalin Date: Wed, 5 Jan 2022 17:27:45 +0600 Subject: [PATCH] use mongoose transaction helper use the helper instead of manually commiting/aborting to deal with transient transaction errors --- website/server/controllers/api-v3/groups.js | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/website/server/controllers/api-v3/groups.js b/website/server/controllers/api-v3/groups.js index 4bf6611c44..fd61284c6b 100644 --- a/website/server/controllers/api-v3/groups.js +++ b/website/server/controllers/api-v3/groups.js @@ -138,19 +138,11 @@ api.createGroup = { } let savedGroup; - const session = await Group.startSession(); - try { - session.startTransaction(); + await Group.db.transaction(async session => { await user.save({ session }); savedGroup = await group.save({ session }); - await session.commitTransaction(); - } catch (error) { - await session.abortTransaction(); - throw error; - } finally { - session.endSession(); - } + }); // Instead of populate we make a find call manually because of https://github.com/Automattic/mongoose/issues/3833 // await Q.ninvoke(savedGroup, 'populate', ['leader', nameFields]);