liquibase-mongodb
liquibase-mongodb copied to clipboard
MongoDB extension for Liquibase
Liquibase MongoDB Extension
Table of contents
- Introduction
- Release Notes
- Implemented Changes
- Connection String Formats
- Getting Started
- Running tests
- Integration
- Contributing
- License
Introduction
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.
Release Notes
Implemented Changes:
A couple of Changes were implemented until identified that majority of the operations can be achieved using db.runCommand()
and db.adminCommand()
- createCollection - Creates a collection with validator create
- dropCollection - Removes a collection or view from the database drop
- createIndex - Creates an index for a collection createIndexes
- dropIndex - Drops index for a collection by keys dropIndexes
- insertMany - Inserts multiple documents into a collection insert
- insertOne - Inserts a Single Document into a collection insert
- 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
Connection String Formats
Standard Connection String Format
mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]] mongodb://mongodb1.example.com:27317,mongodb2.example.com:27017/?replicaSet=mySet&authSource=authDB
DNS Seed List Connection Format
mongodb+srv://[username:password@]host[/[database][?options]] mongodb+srv://server.example.com/ mongodb+srv://:@cluster0.example.com/testdb?authSource=$external&authMechanism=MONGODB-AWS
Getting Started
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
Prerequisites
- Dependencies that have to be available in classpath if run via Liquibase CLI
mongodb-driver-sync:4.2.0
snakeyaml:1.27
jackson-annotations:2.11.3
jackson-core:2.11.3
jackson-databind:2.11.3
Installing
- Clone the project
git clone https://github.com/liquibase/liquibase-mongodb
- Run tests
Running tests
Adjust connection string
Connection url can be adjusted here: url
Connection String Format
Run Integration tests by enabling run-its
profile
Run integration tests
mvn clean install -Prun-its
Run integration test driver backward compatibility
- Produce test containing jar
mvn clean install -Ptest-jar
- Go to test-project
cd test-project
- Run backward compatibility test with provided 3x driver
mvn clean install -Prun-its,mongo-3x
Quick Start Examples
Quick start Application for NoSql liquibase extensions
Integration
Add dependency:
<dependency>
<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-mongodb</artifactId>
<version>${liquibase-mongodb.version}</version>
</dependency>
Java call:
public class Application {
public static void main(String[] args) {
MongoLiquibaseDatabase database = (MongoLiquibaseDatabase) DatabaseFactory.getInstance().openDatabase(url, null, null, null, null);
Liquibase liquibase = new Liquibase("liquibase/ext/changelog.generic.test.xml", new ClassLoaderResourceAccessor(), database);
liquibase.update("");
}
}
Contributing
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
License
This project is licensed under the Apache License Version 2.0 - see the LICENSE.md file for details