Loading Data Into MongoDB With an ApplicationRunner
Explore how to load data into MongoDB on application startup using Spring Boot's ApplicationRunner. Understand combining reactive Flux streams with blocking calls to ensure data is stored before execution completes. This lesson demonstrates a practical method to read lines from a text file, convert them to reactive entities, and store them using a reactive repository inside a blocking environment.
We'll cover the following...
Data loader
By now, we have all the code we need to run our Spring Boot application. However, we don’t have the quotes stored in the database yet. We’ll solve this by reading them from a text version of the book and storing them into MongoDB the first time the application runs.
In the project’s GitHub repository, you’ll see a file containing the ebook in text mode: pg2000.txt. The first time we run the application, every paragraph will be stored as a quote in MongoDB. To achieve this, we inject ...