Hi,
I am playing around with MongoDB got some errors.
I was trying to create the transaction, but getting an error similar to the post here.
This is how my code approximately looks like:
var session = mongoClient.startSession();
try {
session.startTransaction();
var database = client.getDatabase(databaseName);
database.createCollection(session, "somename");
addIndexes(session); // getting database same way
session.commitTransaction();
} catch (RuntimeException ex) {
session.abortTransaction();
throw ex;
} finally {
session.close();
}
I have tried supplying all possible WriteConcerns as transaction options but getting same error.
Full exception message:
com.mongodb.MongoCommandException: Command failed with error 72 (InvalidOptions): 'writeConcern is not allowed within a multi-statement transaction' on server <server address>. The full response is {"operationTime": {"$timestamp": {"t": 1625923453, "i": 1}}, "ok": 0.0, "errmsg": "writeConcern is not allowed within a multi-statement transaction", "code": 72, "codeName": "InvalidOptions", "$clusterTime": {"clusterTime": {"$timestamp": {"t": 1625923453, "i": 1}}, "signature": {"hash": {"$binary": {"base64": "SEQ9iKC3UBcoyz5PuwNWVaSl93k=", "subType": "00"}}, "keyId": 6951399947191189506}}}