MongoDB: Resolving the "TransientError - Transaction aborted" error
NicolasBrondinBernard
Learn how to fix the MongoDB “TransientError – Transaction aborted” error: common causes, best practices (retries, timeouts, sessions), and step-by-step solutions.

Article published on 20/07/2021, last updated on 10/08/2026
The "TransientError" family of errors in MongoDB indicates that an error has occurred but there is no guarantee that this error will happen again if you rerun the same code.
But what does that mean?
This means that the cause of the error does not come from the query (or the set of queries in the case of a transaction), but may come from an external factor.
The simplest example is a micro network outage at the moment of a request: the latter could not execute properly, but if you retry it everything may very well go fine.
In short, TransientError = you can retry the request.
The causes found include the network, possibly a lack of disk space, and other more insidious causes with names and codes that don't give much indication about the origin of the error, such as "NoSuchTransaction".
NoSuchTransaction - Transaction X has been aborted
If this error is familiar to you and you're here, it's surely because you weren't able to find the root cause, and for good reason this error doesn't tell us much, and neither does the documentation.
Let's take the full text of this error:
{ MongoError: Transaction 1 has been aborted.
at server/node_modules/mongodb-core/lib/connection/pool.js:581:63
at authenticateStragglers (/server/node_modules/mongodb-core/lib/connection/pool.js:504:16)
at Connection.messageHandler (server/node_modules/mongodb-core/lib/connection/pool.js:540:5)
...
errorLabels: [ 'TransientTransactionError' ],
operationTime:
Timestamp { _bsontype: 'Timestamp', low_: 2, high_: 1544250067 },
ok: 0,
errmsg: 'Transaction 1 has been aborted.',
code: 251,
codeName: 'NoSuchTransaction',
...
}
Trying to decipher it, we understand that the transaction no longer exists: "NoSuchTransaction".
Why? Because it was cancelled by the system itself: "Transaction 1 has been aborted."
But why was this transaction cancelled?
There's a good chance you received this error after waiting for the transaction to finish for a while. Quite simply because this error indicates that the transaction was cancelled because it was taking too long to execute.
This isn't very obvious in the official documentation, but it is stated that, by default, MongoDB will cancel any transaction running for more than 60 seconds in order to avoid blocking the database for too long.
The solutions
Check that your transaction isn't stuck
Indeed, if there happens to be a problem in your logic code and the execution or the sequence of operations is stuck, then MongoDB will simply stop the transaction in question.
You can then check the execution of each operation outside of your transaction to verify that everything is working properly.
Reduce the execution time
It may be that you have so many operations to perform on the database within your transaction that the total execution time simply exceeds MongoDB's default timeout.
The best solution then will be to find a way to make your transaction execute faster.
If you're using NodeJS, one of the key solutions when looping over a lot of data can be to replace async/await calls with a Promise.all as explained in this article.
Modify MongoDB's configuration
If your business constraints force you to design a transaction that exceeds the default 60-second timeout (which is not recommended), then the last solution will be to modify the database configuration to increase the allowed time for a transaction:
db.adminCommand( { setParameter: 1, transactionLifetimeLimitSeconds: 90 } )
For more information, I invite you to read the official documentation on transactions: https://docs.mongodb.com/manual/core/transactions-sharded-clusters/
No spam. Only free content, news, and ever more resources to level up your skills!
Join +1500 developers
No comments yet