-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Transaction Management
-
None
When running:
ClientSession clientSession = mongoClient.startSession(); clientSession.startTransaction(); collection.insertOne(clientSession, Document.parse("{_id: 1, a: 1}")); collection.insertOne(clientSession, Document.parse("{_id: 2, a: 1}")); clientSession.commitTransaction(); clientSession.close();
Against a 3.6 replicaset or sharded cluster the user gets the following error:
Exception in thread "main" com.mongodb.MongoCommandException: Command failed with error 40415 (Location40415): 'BSON field 'insert.startTransaction' is an unknown field.' on server localhost:27017. The full response is { "operationTime" : { "$timestamp" : { "t" : 1534322289, "i" : 4 } }, "ok" : 0.0, "errmsg" : "BSON field 'insert.startTransaction' is an unknown field.", "code" : 40415, "codeName" : "Location40415", "$clusterTime" : { "clusterTime" : { "$timestamp" : { "t" : 1534322289, "i" : 4 } }, "signature" : { "hash" : { "$binary" : "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "$type" : "00" }, "keyId" : { "$numberLong" : "0" } } } }
Its quite unclear as to what the cause of the actual issue is.
For other scenarios the errors are much clearer:
- Single Node: com.mongodb.MongoClientException: Sessions are not supported by the MongoDB cluster to which this client is connected
- Sharded cluster: com.mongodb.MongoCommandException: Command failed with error 50841 (Location50841): 'Multi-document transactions cannot be run in a sharded cluster.'
The spec states:
startTransaction SHOULD report an error if the driver can detect that transactions are not supported by the deployment.
A wire check would allow for clearer error messages for users trying to use transactions on an older server.