Hi Team,
We are frequently encountering the below error message when trying to transactionally update documents together:
Caused by: com.mongodb.MongoCommandException: Command failed with error 251 (NoSuchTransaction): 'Given transaction number 4 does not match any in-progress transactions. The active transaction number is 3' on server cluster0-shard-00-02.*****.mongodb.net:27017. The full response is {"errorLabels": ["TransientTransactionError"], "ok": 0.0, "errmsg": "Given transaction number 4 does not match any in-progress transactions. The active transaction number is 3", "code": 251, "codeName": "NoSuchTransaction", "$clusterTime": {"clusterTime": {"$timestamp": {"t": 1682465400, "i": 14}}, "signature": {"hash": {"$binary": {"base64": "vqwdne/1kG8A2qNJ4nsqFsx+6V0=", "subType": "00"}}, "keyId": 7187829697743421442}}, "operationTime": {"$timestamp": {"t": 1682465400, "i": 14}}}
We are using mongodb java package org.mongodb:mongodb-driver-core:4.9.1
And the example code is as following:
ClientSession clientSession = _mongoClient.startSession();
clientSession.startTransaction(
TransactionOptions.builder().writeConcern(WriteConcern.MAJORITY).maxCommitTime(1L, TimeUnit.MINUTES).build());
return /* A code block to async calling many _mongoCollection.updateOne(clientSession, filter, document) */
.map(success -> {
session.commitTransaction();
return (Void) null;
}).onFailure(t -> {
session.abortTransaction();
});
Although we did not do a retry in the above logic, I am just wondering why it would hit an issue with transaction ID mismatch, given that the clientSession
is passed in the mongo update?
Thank you!