const session = await mongoose.startSession();
try {
session.startTransaction();
const newUser = await User.create([userData], { session }); // array
await session.commitTransaction();
await session.endSession();
} catch (err: any) {
await session.abortTransaction();
await session.endSession();
throw new AppError(httpStatus.NOT_FOUND, err);
}
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (1)
nice article, one suggestion
you can end session in finally block
finally{
// end session
}