2

How to change transactionLifetimeLimitSeconds in my cloud replica set. Firstly i was creating new session:

var client = new MongoClient(new MongoUrl(_connectionString));           
var session= client.StartSession();

Next

session.StartTransaction();
/* Code that takes longer than 1 minute*/
session.CommitTransaction();

When the code between start and commit transaction ends im getting Error like

Exception thrown: 'MongoDB.Driver.MongoCommandException' in MongoDB.Driver.Core.dll ("Command insert failed: Transaction 1 has been aborted..") Exception thrown: 'MongoDB.Driver.MongoCommandException' in MongoDB.Driver.Core.dll

If the code take less than 1 minute everything is ok.

Wojna
  • 136
  • 1
  • 17

1 Answers1

2

You can call this command db.adminCommand( { setParameter: 1, transactionLifetimeLimitSeconds: 30 } ) like:

var adminDb = client.GetDatabase("admin");
adminDb.RunCommand<BsonDocument>("{ setParameter: 1, transactionLifetimeLimitSeconds: 30 }";

Also, check this transaction option: http://mongodb.github.io/mongo-csharp-driver/2.11/apidocs/html/P_MongoDB_Driver_TransactionOptions_MaxCommitTime.htm, I believe it should help (but I didn't use it personally).

dododo
  • 3,872
  • 1
  • 14
  • 37
  • i was trying MaxCommitTime option but i think it just extend a commit time not whole transaction. I'll will try the second option to get access to admin database but im not sure i have insufficient permissions for that – Wojna Oct 15 '20 at 06:16