Instead of using try/catch when we add the comment to the product we could use the transaction, so if there is an error in calculating the stars/adding the comment to the product document we dont have to delete the comment ourselves but an automatic rollback is performed.
Instead of using try/catch when we add the comment to the product we could use the transaction, so if there is an error in calculating the stars/adding the comment to the product document we dont have to delete the comment ourselves but an automatic rollback is performed.
https://mongoosejs.com/docs/transactions.html