I have the cosmos mongodb server 4.0 in placed and also have
MongoTransactionManager
bean setup and applied @Transactional
On the method in my poc like below:
@Configuration
class Config extends AbstractMongoConfiguration {
@Bean
MongoTransactionManager transactionManager(MongoDbFactory dbFactory) {
return new MongoTransactionManager(dbFactory);
}
}
@Service
class DocumentService {
private final MongoOperations operations;
DocumentService(MongoOperations operations) {
this.operations = operations;
}
@Transactional
void insertDocuments() {
operations.insert(documentOne);
operations.insert(documentTwo);
// manually raise error here
Int error = 1/0
}
}
What I am expecting is it should not insert any record to the DB until it reach the end of the method without any error. In the snippet above, when I am in the debugging , I can see that each insert is being stored in the DB and when error happened, no rollback is being triggered which is completely not ACID at all.
With the same sample, I am able to get the transaction feature working in a pure MongoDB 4.0 server.
And I cannot find any sample or documentation of Java or spring-boot-data-mongo implementation for the transaction feature.
So my question is:
- Does
Azure Cosmos DB MongoDB API 4.0
Transaction feature compatible with spring-boot-starter-data-mongodb? - Do we have any sample for Java and spring-boot-starter-data-mongodb for transaction feature?
Dependencies I used:
Spring-boot-starter-parent 2.4.3 and spring-boot-starter-data-mongodb