Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you load initial data in MongoDB through Spring Boot?

Is it possible to load initial data in a MongoDB database using src/main/resources/data.sql or by any other file?

I understand that data.sql is used for SQL DB's whereas MongoDB is a NOSQL DB. But just wanted to know if there is any equivalent of data.sql for NOSQL DB's.

While googling I found out this SO link (Spring Boot - Loading Initial Data) which does what I am looking for but still it's not a standalone file data.sql.

like image 584
Nital Avatar asked Dec 06 '17 15:12

Nital


People also ask

What is spring boot starter data MongoDB?

last modified May 10, 2022. Spring Boot MongoDB tutorial shows how to access data in MongoDB in Spring Boot framework. Spring is a popular Java application framework and Spring Boot is an evolution of Spring which helps create stand-alone, production-grade Spring based applications easily.


1 Answers

To load initial data you can use db migration tool like MongoBee

It's very useful option to handle data initialization in java. You just need to configure @Bean public Mongobee mongobee in your spring boot and setup component scan for data ChangeLogs where data creation actually happens.

like image 157
A. Malynskyi Avatar answered Oct 17 '22 08:10

A. Malynskyi