There is a liquibase mongodb project which can be used. You can take a look at this project. There is a db.changelog-master.json where the schema creation is defined as a first changelog (you can define more) and as you can see in the test just defined the container, set the spring.data.mongodb.uri
and manually run the migration due to spring boot does not offer autoconfigure for liquibase mongodb extension.
@Container
private static final MongoDBContainer mongo = new MongoDBContainer("mongo:4.0.10");
@Autowired
private PersonRepository repository;
@DynamicPropertySource
static void mongoProperties(DynamicPropertyRegistry registry) {
registry.add("spring.data.mongodb.uri", mongo::getConnectionString);
}
@Test
void test() throws LiquibaseException {
var database = (MongoLiquibaseDatabase) DatabaseFactory.getInstance().openDatabase(mongo.getReplicaSetUrl("test"), null, null, null, null);
var liquibase = new Liquibase("db/changelog/db.changelog-master.json", new ClassLoaderResourceAccessor(), database);
liquibase.update("");
var books = this.repository.findAll();
assertThat(books).hasSize(3);
}
This sample project is based in spring boot too.
Also, check Initializing a fresh instance