Reputation: 111
I'm using mongock to generate the initial data on the database and so far it's working fine for Country
but still a long way to go
@ChangeUnit(id="country-initializer", order = "1")
public class CountryInitializerCU {
@BeforeExecution
public void beforeExecution(MongoTemplate mongoTemplate) {
mongoTemplate.createCollection(COUNTRY_COLLECTION_NAME);
}
@RollbackBeforeExecution
public void rollbackBeforeExecution() {
// do nothing
}
@Execution
public void execution(CountryRepository countryRepository) {
List<Country> countries = new ArrayList<>();
countries.add(new Country("AM", "ARM", "Armenia"));
countries.add(new Country("AL", "ALB", "Albania"));
countries.add(new Country("AO", "AGO", "Angola"));
countries.add(new Country("BS", "BHS", "Bahamas"));
countries.add(new Country("BY", "BLR", "Bahamas"));
// TODO
countryRepository.saveAll(countries);
}
@RollbackExecution
public void rollbackExecution(MongoTemplate mongoTemplate) {
mongoTemplate.dropCollection(COUNTRY_COLLECTION_NAME);
}
}
The problem that I see now is that I need to to the same for Places
. The problem is that Places
have 140.000 records
. Imagine filling that by hand. I have those places in a 200MB json file that I could use instead of filling manually.
What is the best approach?
Upvotes: 0
Views: 1285
Reputation: 3766
What you may do here is:
Country
instances and save them into the database as you are doing right now.Upvotes: 1