Reputation: 3331
I'm using Mongock for migrating and initializing my MongoDB database with Spring-Boot. What I need is a way to check when all the changelogs have been applied.
How can I check if Mongock completed all the changelogs/changesets?
I found that Mongock creates a collection mongockLock in which there is an entry while the migration is running.
Would it be enough to check for the absence of any document in the above collection to conclude that Mongock has completed the changelogs?
How can I query for the documents in this collection?
Upvotes: 0
Views: 1957
Reputation: 1533
With spring boot, there are two approaches to use Mongock, like shown in Mongock's documentation:
Via properties, using @EnableMongock
mongock:
runner-type: InitializingBean
With the builder approach
@Bean
public MongockInitializingBeanRunner mongockInitializingBeanRunner(
ApplicationContext springContext,
MongoTemplate mongoTemplate){
return MongockSpring5.builder()
.setDriver(SpringDataMongo3Driver.withDefaultLock(mongoTemplate))
.addChangeLogsScanPackage("your_changeLog_package_path")
.setSpringContext(springContext)
.buildInitializingBeanRunner();
}
Upvotes: 1
Reputation: 1533
first at all, the mongockLock
collection is just the collection for the distributed pessimistic lock. It's the mechanism Mongock uses to ensure that a changeLog is only run by an instance at a time. If it's successful, just once(unless flag runAlways is true, in which case will obviously run every time).
So mongockLock is not what you are looking for
There are 3 ways you can check your migration has run successfully, or not.
failFast
in any ChangeSet, the Mongock runner will throw an exception if any of the changeLogs failsUpvotes: 1