4

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?

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

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);
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.