use mongoose transaction helper
use the helper instead of manually commiting/aborting to deal with transient transaction errors
This commit is contained in:
@@ -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]);
|
||||
|
||||
Reference in New Issue
Block a user