Member-only story
Configuring MongoDB Liquibase in Spring Boot
In this short article, I will describe how to configure Liquibase for use in Spring Boot.
If you need help with creating applications, contact me on Fiverr!
The version of Spring Boot we will be using is 2.7.4
. The dependencies we need are as follows.
<dependency>
<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-mongodb</artifactId>
<version>4.15.0</version>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>4.15.0</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>3.4.3</version>
</dependency>
We need to define the url to connect to the Mongo database, the username and password of the user that has writing and reading permissions and also the changeLogFilePath
which is the path to the changelog file. In the following example, the changelog file is stored in resources > db > changelog
.
String url = "";
String username = "";
String password = "";
String changeLogFilePath = "classpath:db/changelog/changelog.json";
Next, we need to create the MongoLiquibaseDatabase
class which opens the connection to the Mongo database.