This is a Liquibase extension for MongoDB support.
It resulted as an alternative to existing MongoDB evolution tools.
Majority of them are basically wrappers over db.eval
shell method that is deprecated staring from MongoDB 4.2.
In order to call specific mongo-java-driver
specific methods,
Liquibase turned to be the most feasible tool to extend as it allows to define change sets to fit driver methods arguments.
A couple of Changes were implemented until identified that majority of of the operations can be achieved using db.runCommand()
and db.adminCommand()
- createCollection - Creates a collection with validator
- createIndex - Creates an index for a collection
- insertMany - Inserts multiple documents into a collection
- insertOne - Inserts a Single Document into a collection
- runCommand - Provides a helper to run specified database commands. This is the preferred method to issue database commands, as it provides a consistent interface between the shell and drivers
- adminCommand - Provides a helper to run specified database commands against the admin database
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
mongo-java-driver:3.10.2
- Clone the project
- Run tests
Connection url can be adjusted here: db.connection.uri
Integration tests are run by enabling run-its
profile
mvn clean install -Prun-its
<dependency>
<groupId>com.mastercard.liquibase</groupId>
<artifactId>liquibase-mongodb</artifactId>
<version>${liquibase-mongodb.version}</version>
</dependency>
MongoConnection mongoConnection;
MongoExecutor mongoExecutor;
MongoLiquibaseDatabase database;
mongoConnection = new MongoConnection("mongodb://localhost:27017/test_db?socketTimeoutMS=100&connectTimeoutMS=100&serverSelectionTimeoutMS=100");
//Can be achieved by excluding the package to scan or pass package list via system.parameter
//ServiceLocator.getInstance().getPackages().remove("liquibase.executor");
//Another way is to register the executor against a Db
database = (MongoLiquibaseDatabase) DatabaseFactory.getInstance().findCorrectDatabaseImplementation(mongoConnection);
database.setConnection(mongoConnection);
mongoExecutor = new MongoExecutor();
mongoExecutor.setDatabase(database);
ExecutorService.getInstance().setExecutor(database, mongoExecutor);
final Liquibase liquibase = new Liquibase("liquibase/ext/changelog.create-users.test.xml", new ClassLoaderResourceAccessor(), database);
liquibase.update("{}");
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
This project is licensed under the Apache License Version 2.0 - see the LICENSE.md file for details