7

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.

iDroid
  • 1,140
  • 1
  • 13
  • 30
  • Mongobee has been abandoned, but Mongock has been there for a little while and it's up and running and providing good feature and support. The documentation is at https://www.mongock.io/ – Mongock team Oct 04 '20 at 09:45

4 Answers4

11

The mongodb extension for Liquibase just came out. Since you are familiar with Liquibase you might the extension. https://github.com/liquibase/liquibase-mongodb

Mike Olivas
  • 313
  • 2
  • 8
4

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.

Mongock team
  • 1,188
  • 5
  • 9
  • I am not a mongock dev team member, but Mongock is implemented in our team in production(Citi innovation), and I can highly recommend it – Roie Beck Apr 20 '21 at 06:51
3

There is this one - mongock.io which is similar like how Liquibase work and works perfectly. Below is the github URL: https://github.com/cloudyrock/mongock

Yazik
  • 71
  • 3
  • While this code may answer the question, it would be better to explain how it solves the problem without introducing others and why to use it. – jnovack Oct 04 '20 at 20:36
1

I'm not familiar with Liquibase and I'm not sure what you mean by "Must be able to extract the changes before execution", but here is another useful MongoDB-specific option that is similar to node-migrate: https://www.npmjs.com/package/migrate-mongo

Also, an article explaining the how / why to use it: https://medium.com/javascript-in-plain-english/developer-story-db-migrations-mongodb-edition-7b36db8f2654

Kenny DiFiore
  • 151
  • 1
  • 6