Reputation: 186
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]
Upvotes: 11
Views: 5013
Reputation: 458
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();
Upvotes: 34