Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure flapdoodle embedded mongodb for transaction

I'm using "Flapdoodle Embedded MongoDB" for integartion test. It works fine. After adding the transaction manager, I have the following error:

org.springframework.data.mongodb.UncategorizedMongoDbException: This MongoDB deployment does not support retryable writes. Please add retryWrites=false to your connection string.

Here is my application.properties file. I'm not using a connection string for tests. I only added the database version.

de.flapdoodle.mongodb.embedded.version=5.0.5

I tried to add an implementation of AbstractMongoClientConfiguration. But, it didn't fix the issue.

@Configuration
public class EmbededMongoTransactionConfig extends AbstractMongoClientConfiguration {

@Value("${spring.data.mongodb.database}")
private String database;

@Bean
MongoTransactionManager mongoTransactionManager(MongoDatabaseFactory dbFactory) {
    return new MongoTransactionManager(dbFactory);
}

@Bean
MongodArguments mongodArguments() {
    return MongodArguments.builder().replication(Storage.of(database, 10)).build();
}

@Override
protected String getDatabaseName() {
    return database;
}
}

I'm using the following dependencies (springboot 2.7.8):

   <dependency>
        <groupId>de.flapdoodle.embed</groupId>
        <artifactId>de.flapdoodle.embed.mongo</artifactId>
        <version>4.6.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>de.flapdoodle.embed</groupId>
        <artifactId>de.flapdoodle.embed.mongo.spring27x</artifactId>
        <version>4.6.0</version>
        <scope>test</scope>
    </dependency>

Can you help with configuring flapdoodle mongoDb to work with a transaction?

like image 224
GHASSEN Avatar asked Sep 05 '25 21:09

GHASSEN


1 Answers

This worked for me:

https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo.spring/blob/main/HowTo.md#transactions

Tough worked well on my local machine whereas failed in docker container. No info on this particular case so far

like image 162
user655419 Avatar answered Sep 08 '25 12:09

user655419