await tran_session.withTransaction(async () => {
const id_arr = Object.keys(req.get_tar.blocked).map((key) => {
return ObjectId(key);
});
await Promise.all([
await user.updateOne( // does not roll back changes if "await" keyword is removed
{ email: req.user.email },
{ $pull: { tar: { name: { $eq: req.params.name } } } },
{ session: tran_session }
),
await user.update( // does not roll back changes if "await" keyword is removed
{ _id: { $in: id_arr } },
{
$unset: {
[`blocked_by.${req.user._id}_${req.get_tar.name}`]:
undefined,
},
},
{ session: tran_session, multi: true }
),
]);
}, tran_option);
If I call the update
functions with the await
and if there is an error thrown, the changes will not be rolled back.
Why is this?