Transaction Errors

We are using the concept of transactions to commit the data to the DB. These many days we didn’t face any issues when using transactions whereas recently we encounters an issue where we are doing multiple update to different collections in single transaction. While performing this kind of scenario we are getting Mongo errors.

Please find the details of the errors.

Command update failed: Given transaction number 46 does not match any in-progress transactions. The active transaction number is 45.

MongoDB.Driver.MongoCommandException: Command update failed: Only servers in a sharded cluster can start a new transaction at the active transaction number.

We suspect this issue could be because of not having Shraded clusters. Could you please confirm, if this can be an cause for the same.

Hi Preeti_Islur, I’m facing the same issue without having shraded clusters doing transactions but only in one collection. Any idea where it comes from?
Regards, Daniel

Hi @Daniel_Camarena and welcome!

Please note that MongoDB Multi-Document Transactions are supported in both replica sets and sharded clusters (sharded cluster consists of replica sets)

This error is likely to be related to sessions. Could you provide:

  • The MongoDB driver and version that you use
  • A minimal reproducible code to show the transaction operation
  • Any error logs happening on the replica set during/around the error that you’ve received.


Hi Wan,

first of all thanks for your quick reply. Here the answers to your questions:

  1. Question
  • NuGet MongoDB.Driver Version 2.13.2
  • NuGet MongoDB.Bson Version 2.13.2
  • NuGet MongoDB.Bson.NodaTime Version 3
  1. Question
    Unfortunately I already removed that code. I have it in git, but the application itself is tremendous, so this wouldn’t help. What we basically do is we start an transaction in the DAL and every other part in the program reacts on events and uses the non-mongo-specific-functions of the DAL.

I was about to implement a part in the program which collected an exception and tried to write them as a document in the DB. Obviously, DB-exceptions telling me that the transaction was canceled for instance, resulted in an exception which I tried to store to the DB. Checking if an transaction is already active (using session.IsInTransaction) returns true even if the server session is not in transaction. I reported this “bug” before with code and the answer was that it “works as designed”:
In other words: If the transactions is canceled server side the client has no chance to detect it apart from running into the next exception telling me that the transaction is not active or like in this case that I’m not able to start transaction x+1.

Back to this issue:
To be honest, later on I thought that I just faced this problem/exceptions when I was standing in the debugger holding the open transaction too long and the server canceled it. With this DB-timeout-exception I tried to insert another document with the following code:

                if (session.IsInTransaction())
                    session.WithTransaction(() =>

Hope you can rebuild this case. Anyway I try to create an unit test example this weekend which reproduces the error. I’ll let you know here. If you are already aware of that behavior and you don’t need it let me know.

3.) With the unit test you should be able to see what’s happening on your system.

Thanks, cheers, Daniel