Data changes over time.
Mongo Documents vs Java Objects:
- A change in a Mongo Document will impact serialization / deserialization process
- A change in Mongo Document will impact the queries
- Changes to collections will also impact queries
Implementation options:
- Manual migrations using scripts (to be avoided at all cost)
- Create migration component ourselves
- Needs
- Version detection (& automatic upgrade)
- Simple configuration
- Logging
- Pro
- Complete control
- Can meet every aspect of our needs
- Con
- Requires more time to develop
- Is not trivial to create
- Needs
- Use an existing migration framework
- Pro
- Saves time
- Increased focus on the application domain
- Con
- The data migration process is not fully under our control
- Some applications need more features than frameworks offer
- Pro
Dependency:
<dependency>
<groupId>com.github.mongobee</groupId>
<artifactId>mongobee</artifactId>
</dependency>
Configure bean:
@Bean
public Mongobee mongobee() {
Mongobee runner = new Mongobee(mongoUri);
runner.setEnabled(true);
runner.setChangeLogsScanPackage("yourdomain.*");
runner.setMongoTemplate(this.mongoTemplate);
return runner;
}
Changelog:
@ChangeLog(order = "001")
public class DBChangeLog001 {
@ChangeSet(order = "001", id = "seedCrew", author = "Steven")
public void seedCrewMembers(MongoTemplate mongoTemplate) {
// ...
}
}
We can go here for more information and examples.
- Liquibase MongoDB Extension
- Mongock