Release process for MongoDB changes

Viewed 3890

When its RDBMS, I used Liquibase to deploy the changes in the target database. That has support for multi-tenancy & roll back to different versions.

In Mongo, I tried to find the equivalent library and found the below.

  1. https://github.com/mongobee/mongobee - Requires java skillset. Last update was 2 Years ago.
  2. https://github.com/coldze/mongol - Stick to just Json. Low reputation.
  3. https://github.com/mongeez/mongeez - Kind of promising but very outdated.
  4. https://github.com/tj/node-migrate - Done in jS, has reputation better than others, but lot of learning required to be familiar with this framework IMO.

For me the criteria are,

  1. Upgrade from one version to any new version must be possible.
  2. Downgrade from the current version to any old version must be possible ( should have the feasibility to do the complex migration. Ex, refer to the different collections and assign a computed value from the output.
  3. Must be able to extract the changes before execution. For verification purposes mostly. Otherwise, during new build deployment, the changes alone to be executed.
  4. Easy to adopt, so a lot of learning should be avoided.

You have some other working concept, eager to know. Thanks,

A.

4 Answers

If you are using Java, a very good option(I'd say probably the best) is Mongock.

It provides everything you need and there are very good features in the road map.

To get started(if using Spring 5 and spring data 3), you just need :

  1. Add Mongock to your pom
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.github.cloudyrock.mongock</groupId>
            <artifactId>mongock-bom</artifactId>
            <version>4.1.17</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
<!-- ... -->
<dependency>
    <groupId>com.github.cloudyrock.mongock</groupId>
    <artifactId>mongock-spring-v5</artifactId>
</dependency>

<dependency>
    <groupId>com.github.cloudyrock.mongock</groupId>
    <artifactId>mongodb-springdata-v3-driver</artifactId>
</dependency>
  1. Add your Spring and MongoDB dependencies to your pom
  2. Add minimum configuration
mongock:
  change-logs-scan-package:
    - your.package.for.changelogs
  1. Create your changeLog in the package indicated previously indicated: your.package.for.changelogs
@ChangeLog(order = "001")
public class DatabaseChangelog {
  
  @ChangeSet(order = "001", id = "changeWithoutArgs", author = "mongock")
  public void yourChangeSet() {
   // your migration here
  }
}
  1. Add Mongock annotation to your SpringBoot application
@EnableMongock
@SpringBootApplication
public class App {
  public static void main(String[] args) {
    new SpringApplicationBuilder().sources(App.class).run(args);
  }
}

This is only a quick introduction on how it works. Please a look to the documentation for more information.

Disclosure: I am one of the Mongock authors.

Related