Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

260
Views
Execute MongoDB script on Spring Boot start

I need to initialize a Mongo DB with some script file like Spring do with JPA and import.sql file.. but how?

Can someone help me?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You could use something similar that's done by mongeez. This is basically a starter for spring-boot that runs scripts before spring-data-mongodb beans are initialized.

over 4 years ago · Santiago Trujillo Report

0

You could tag along and leverage spring-boot's initialization lifecycle, where after wiring the beans, it executes all CommandLineRunner beans.

@SpringBootApplication
public class YourApplication {
    final Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private MongoRepository repo;

    @Bean
    CommandLineRunner preLoadMongo() throws Exception {
        return args -> {
            //repo.doSOmethingInMongoDB
       }

    public static void main(String[] args) {
        SpringApplication.run(YourApplication.class, args);
    }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!