Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongoose Transactions - MongoError: Commited to Aborted

I have a problem with my Mongo database.

I am using Mongoose Transactions to save multiple documents to my database and they are all saved in the end and the transaction is commited, but I still get a MongoError and my app crashes:

MongoError: Attempted illegal state transition from [TRANSACTION_COMMITTED] to [TRANSACTION_ABORTED]

like image 337
mladjo Avatar asked Aug 05 '19 08:08

mladjo


1 Answers

For me the problem was that I was not waiting for transaction commit. So I change this:

session.commitTransaction(); 
session.endSession();

Into:

await session.commitTransaction(); 
session.endSession();
like image 161
bogdan ioan Avatar answered Nov 20 '22 14:11

bogdan ioan