mongock | Lightweight MongoDB migration tool for Java | Microservice library

 by   cloudyrock Java Version: 1.16 License: Apache-2.0

kandi X-RAY | mongock Summary

kandi X-RAY | mongock Summary

mongock is a Java library typically used in Architecture, Microservice, MongoDB, Spring Boot applications. mongock has no vulnerabilities, it has build file available, it has a Permissive License and it has low support. However mongock has 5 bugs. You can download it from GitHub, Maven.

Lightweight MongoDB migration tool for Java
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              mongock has a low active ecosystem.
              It has 266 star(s) with 38 fork(s). There are 8 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 15 open issues and 144 have been closed. On average issues are closed in 17 days. There are 1 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of mongock is 1.16

            kandi-Quality Quality

              mongock has 5 bugs (0 blocker, 2 critical, 0 major, 3 minor) and 335 code smells.

            kandi-Security Security

              mongock has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              mongock code analysis shows 0 unresolved vulnerabilities.
              There are 2 security hotspots that need review.

            kandi-License License

              mongock is licensed under the Apache-2.0 License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              mongock releases are available to install and integrate.
              Deployable package is available in Maven.
              Build file is available. You can build the component from source.
              mongock saves you 6419 person hours of effort in developing the same functionality from scratch.
              It has 12842 lines of code, 2037 functions and 319 files.
              It has medium code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed mongock and discovered the below as its top functions. This is intended to give you an instant insight into mongock implemented functionality, and help decide if they suit your requirements.
            • Executes the migration
            • Execute the change set
            • Prepare change log service
            • Rollback changes if present
            • Ensures the default lock is true
            • Refreshes the lock
            • Handle lock exception
            • Wait for the lock to be acquired
            • Get executor by operation
            • Sets the runner if it is enabled
            • Returns a new MongoSync4Driver with the given number of times
            • Compares two triple objects
            • Returns a copy of this database
            • Returns a new object with lock strategy
            • Executes the given operation in a new transaction
            • Returns a copy of this driver
            • Returns the set of client session - related dependencies
            • Create an instance of the specified type
            • Executes the given operation in a transaction
            • Returns a string representation of the change set item
            • Acquires the default lock
            • Waits until the specified table is not active
            • Executes migration
            • Compare by order
            • This method executes the given runnable in a transaction
            • Starts the lock daemon
            Get all kandi verified functions for this library.

            mongock Key Features

            No Key Features are available at this moment for mongock.

            mongock Examples and Code Snippets

            No Code Snippets are available at this moment for mongock.

            Community Discussions

            QUESTION

            MongoDB: Search by field with date and update it by condition
            Asked 2022-Feb-27 at 18:47

            Please tell me how can I fulfill the following condition - if the time in the info.startDate field is not equal to 00 hours, increase the date (2021-05-27) by 1 day ahead, set the time to 00:00:00.000Z. I tried to do it clumsily, through Mongock, getting all the elements of the collection and doing a check through LocalDateTime, but my heap overflowed, which is logical because the collection is large. How can I do this through Mongock or at least a manual request to MongoDB. So far I've only written this:

            ...

            ANSWER

            Answered 2022-Feb-27 at 18:47

            If you're using Mongo version 5.0+ then you can use $dateTrunc and $dateAdd to achieve this quite easily, like so:

            Source https://stackoverflow.com/questions/71287272

            QUESTION

            How to test change unit in mongock with its multiple attributes/lifecycle methods?
            Asked 2022-Feb-17 at 10:48

            We recently migrated from MongoBee to Mongock, and with Mongock 5 version the @ChangeLog and @ChangeSet are depricated. Writing the @ChangeUnit is easy enough and rollback methods are very helpful.

            However, I'm unable to figure out how to write a test simulating the migration in test DB and validating the changes in DB, as there are @BeforeExecution, @RollbackBeforeExecution, @Execution and @RollbackExecution attributes or lifecycle methods in a @ChangeUnit.

            Earlier, I used to just call the method with @ChangeSet annotation like

            ...

            ANSWER

            Answered 2022-Feb-17 at 10:48

            In the new version 5, the basic change is that a ChangeUnit holds the unit of execution. That's normally done in the method annotated with @Execution, so the first approach is just doing the same you are doing but calling the @Execution method:

            Source https://stackoverflow.com/questions/71154969

            QUESTION

            Best way to init database with specific data by environment (dev, pprod, prod) using Mongock
            Asked 2021-Jul-05 at 10:58

            I'm using Mongock to init a MongoDb database with some configs, An array of authorized users by calling system. {systemId: 'a', authorizedUsers: ['user1', user2]}.

            My problem come from the fact that in dev user1 and user2 are authorized but in prod only user1 is authorized.

            • is it better to add an env property {env: 'dev', systemId: 'a', authorizedUsers: ['user1', user2]} and use it as a filter when we search for authorized users ? The downside is to have different configs available in DB and we need to choose the right one.
            • Or is it better to read in Mongock init function (the ChangeSet) the env where Mongock is running on and init the right data ? The downside is that we can't test the correctness of the init before to be in the right environnement
            • A better solution ?

            Thank you in advance for your responses

            Edit to clarify the two options

            • Option 1
            ...

            ANSWER

            Answered 2021-Jul-05 at 09:15

            If I am not wrong, I see two parts in this problem

            1. Where to store the user's configuration/how to pass it to Mongock
            2. Based on that configuration, initialise your MongoDB database.

            I guess we both agree the second step is clear: Mongock somehow takes the configuration and performs the migration.

            Regarding of how to provide that configuration to Mongock, in your first option you mention to add a field for the environment, right? Are you saying you have the same database for production and dev environments? In my opinion, unless you have a really good reason for it, I wouldn't recommend that. In my ideal world, you would have a database per environment, so that field for environment is not needed. Mongock just needs to take the information from that collection that has been previously added.

            Then the issue is how that configuration data about users is added to the database. If it can be hardcoded from your java code you can easily do it in Mongock. If you are using Spring you can use @Profile to talle which changeLog execute in which environment.

            If not, another idea is passing those users as environment variables or configuration. If you are using kubernetes, ansible of that kind of tool, providing it by environment variable is not a bad idea. But I guess I don't have enough information to get more committed with any option.

            Source https://stackoverflow.com/questions/68228005

            QUESTION

            Mongock failed: NoClassDefFoundError org/springframework/data/mongodb/MongoDatabaseFactory
            Asked 2021-Apr-28 at 17:08

            I'm using the following pom in my spring boot app:

            ...

            ANSWER

            Answered 2021-Apr-28 at 17:08

            That's due to incompatible versions.

            As you can see in this compatibility table, the version of Mongock you are using is compatible with spring-data 3.x, but you are using 2.x instead.

            Mongock provides two drivers for spring-data, mongodb-springdata-v3-driver, for spring-data 3.x and mongodb-springdata-v2-drver for spring-data 2.2.X

            I have a couple of suggestions:

            1. Either upgrade your spring-data dependency to 3.x, or use mongodb-springdata-v2-drver(first one recommended)
            2. Use dependency management so you don't need to specify the version for each dependency. You can do it for spring and for Mongock

            With that you should fix your issue ;)

            Source https://stackoverflow.com/questions/67296369

            QUESTION

            Mongock migration failure with transaction
            Asked 2021-Apr-15 at 12:29

            I'm running a spring boot 2.4.3 app and I have a mongodb 4 cluster which supports transactions(I run it locally using run-rs). I'm also using spring data mongodb. I'm trying to integrate mongock(latest version - 4.3.8) for db migrations but I face a problem, which I can't resolve. As we know the the latest version of mongock is using transactions by default. I have the following changeset which just creates a mongodb collection for one of my entities.

            ...

            ANSWER

            Answered 2021-Apr-15 at 12:29

            As you have mentioned, MongoDB transaction model has some limitations. Please see official MongoDB documentation.

            Having that into account, you cannot wrap that operation in a transaction, so you cannot use it in a standard ChangeLog, if you are using transactions.

            However, the good new i that, as always :D, Mongock team thought about it and will provide a mechanism for pre-transactions operations.

            We expect to have a release candidate ready around June. However, if this is an urgent need, please send us an email to dev@cloudyrock.io and we'll try to find a solution.

            Source https://stackoverflow.com/questions/67076023

            QUESTION

            Will mongock work correctly with kubernetes replicas?
            Asked 2021-Apr-01 at 07:08

            Mongock looks very promising. We want to use it inside a kubernetes service that has multiple replicas that run in parallel.

            We are hoping that when our service is deployed, the first replica will acquire the mongockLock and all of its ChangeLogs/ChangeSets will be completed before the other replicas attempt to run them.

            We have a single instance of mongodb running in our kubernetes environment, and we want the mongock ChangeLogs/ChangeSets to execute only once.

            Will the mongockLock guarantee that only one replica will run the ChangeLogs/ChangeSets to completion?

            Or do I need to enable transactions (or some other configuration)?

            ...

            ANSWER

            Answered 2021-Feb-23 at 10:04

            I am going to provide the short answer first and then the long one. I suggest you to read the long one too in order to understand it properly.

            Short answer

            By default, Mongock guarantees that the ChangeLogs/changeSets will be run only by one pod at a time. The one owning the lock.

            Long answer

            What really happens behind the scenes(if it's not configured otherwise) is that when a pod takes the lock, the others will try to acquire it too, but they can't, so they are forced to wait for a while(configurable, but 4 mins by default)as many times as the lock is configured(3 times by default). After this, if i's not able to acquire it and there is still pending changes to apply, Mongock will throw an MongockException, which should mean the JVM startup fail(what happens by default in Spring).

            This is fine in Kubernetes, because it ensures it will restart the pods. So now, assuming the pods start again and changeLogs/changeSets are already applied, the pods start successfully because they don't even need to acquire the lock as there aren't pending changes to apply.

            Potential problem with MongoDB without transaction support and Frameworks like Spring

            Now, assuming the lock and the mutual exclusion is clear, I'd like to point out a potential issue that needs to be mitigated by the the changeLog/changeSet design.

            This issue applies if you are in an environment such as Kubernetes, which has a pod initialisation time, your migration take longer than that initialisation time an the Mongock process is executed before the pod becomes ready/health(and it's a condition for it). This last condition is highly desired as it ensures the application runs with the right version of the data.

            In this situation imagine the Pod starts the Mongock process. After the Kubernetes initialisation time, the process is still not finished, but Kubernetes stops the JVM abruptly. This means that some changeSets were successfully executed, some other not even started(no problem, they will be processed in the next attempt), but one changeSet was partially executed and marked as not done. This is the potential issue. The next time Mongock runs, it will see the changeSet as pending and it will execute it from the beginning. If you haven't designed your changeLogs/changeSets accordingly, you may experience some unexpected results because some part of the data process covered by that changeSet has already taken place and it will happen again.

            This, somehow needs to be mitigated. Either with the help of mechanisms like transactions, with a changeLog/changeSet design that takes this into account or both.

            Mongock currently provides transactions with “all or nothing”, but it doesn’t really help much as it will retry every time from scratch and will probably end up in an infinite loop. The next version 5 will provide transactions per ChangeLogs and changeSets, which together with good organisation, is the right solution for this.

            Meanwhile this issue can be addressed by following this design suggestions.

            Source https://stackoverflow.com/questions/66324374

            QUESTION

            Mongock inserting duplicate changeset on runAlways=true
            Asked 2021-Mar-31 at 06:48

            My application uses mongock 4.1.19 and when ever there is a changeSet with runAlways=true, there are duplicate entries getting created in the dbchangelog collection.

            the below line does not seem to consider already executed case and may be resulting in duplicate changelog entries

            Any pointers on how this can be addressed

            https://github.com/cloudyrock/mongock-core/blob/91d15d65a22234f4a2e8d28c759d0641d36750e0/mongock-runner/mongock-runner-core/src/main/java/com/github/cloudyrock/mongock/runner/core/executor/MigrationExecutor.java#L139

            Below Logger logged at startup - RE-APPLIED - ChangeEntry{...}

            ...

            ANSWER

            Answered 2021-Mar-31 at 06:48

            It's not really duplicated. It creates a changelog entry per execution.

            However, we understand this is not the more common desired behaviour, we are releasing a bugfix(4.3.8) for version 4 in the next days, probably today.

            In version 5, which is under development, we'll keep this by default, plus updating the last_execution field we'll add, and add the option to insert a new entry per execution if desired.

            Source https://stackoverflow.com/questions/66848745

            QUESTION

            Error creating mongock bean when deploying on docker
            Asked 2021-Mar-14 at 22:30

            I am using Mongck to migrate data in my Spring Boot application. Spring Boot application runs perfectly locally. But when running on docker, the following error occurs:

            ...

            ANSWER

            Answered 2021-Mar-14 at 22:30

            As discussed in this Github issue, the issue was resolved by upgrading to version 4.3.7.

            Source https://stackoverflow.com/questions/66610729

            QUESTION

            How to add new field to all documents in a collection trough Mongock?
            Asked 2021-Mar-12 at 09:12

            I have a Collection of documents that looks like:

            ...

            ANSWER

            Answered 2021-Feb-26 at 23:06

            Anything you can do with normal MongoTemplate, you can do it as well with MongockTemplate.

            In this case, you can tune the UpdateOptions and some other stuff, but it can be as easy as

            Source https://stackoverflow.com/questions/66355532

            QUESTION

            Is it safe to run mongock with a continuously running application?
            Asked 2021-Feb-26 at 11:39

            We have an application that runs as a 24x7 service in Kubernetes, and we can't take it down to run our migration scripts. I just want to verify that the mongock framework won't interfere with our application's operations - for instance, by locking a collection for an excessively long period of time.

            I know the question sounds very broad, as the impacts/effects of a migration depend on the code we write in our ChangeLog/ChangeSets.

            But I'm wondering whether the mongock framework itself has any effect on mongo collections other than its own internal collections (mongockChangeLog and mongockLock)

            For instance, does mongock hold any locks on mongo collections other than its own?

            I'm assuming that the lock owned by mongockLock won't have an effect on any collection other than mongockChangeLog.

            Likewise, when transactions are enabled, does mongock own any transactions that might impact or affect the transactions owned by our code?

            ...

            ANSWER

            Answered 2021-Feb-26 at 11:39

            Your institution is right. Mongock's lock is just internal. Also it's worthy knowing that you can configure how long this lock is taken for, how long Mongock waits for it, if it cannot acquire it and how long it will be trying. All that it's in the Mongock's documentation

            Speaking about the transactions, Mongock delegates completely the transaction to the underneath framework. I don't fully understand your question, but I can explain which type of transactions are offered by Mongock and you can have a better understanding of the impact.

            • All or nothing: The entire Mongock process is wrapped in a transaction, if it fails at any point, the entire migration is rolled back.(currently provided)
            • Per changeSet(method): Every changeSet successfully executed is committed. If it fails in the middle, it's rolled back.(Will be provided in version 5)
            • Per changeLog(class): The entire changeLog class is wrapped in a transaction, so it will be committed only if all its changeSets are successfully executed.(Will be provided in version 5)

            General speaking, the recommended way to organise your migrations is per changeLog. A changeLog should represent a migration step, it shouldn't be designed in a feature approach. For example if you have in your model Client and Bill, you shouldn't design a changeLog for Client and another for Bill, having in them the different migration you apply over the time. Instead, you should do it in such a way that a changeLog represent a migration step, affecting the entire model, so you can identify your migration history through your changeLogs. From this point of view, Mongock's best practice is to use per changeLog transactions

            Source https://stackoverflow.com/questions/66361594

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install mongock

            You can download it from GitHub, Maven.
            You can use mongock like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the mongock component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

            Support

            Please, see our recently published documentation in here. Although it has been published, it is still under development and there may be some sections unfinished or missing.
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            Install
            Maven
            Gradle
            CLONE
          • HTTPS

            https://github.com/cloudyrock/mongock.git

          • CLI

            gh repo clone cloudyrock/mongock

          • sshUrl

            git@github.com:cloudyrock/mongock.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link