Let's use the Command-line Runner to insert some data into ReactiveMongo. The following snippet shows the details added to SpringReactiveExampleApplication:
@Bean
CommandLineRunner initData(
StockMongoReactiveCrudRepository mongoRepository) {
return (p) -> {
mongoRepository.deleteAll().block();
mongoRepository.save(
new Stock("IBM", "IBM Corporation", "Desc")).block();
mongoRepository.save(
new Stock("GGL", "Google", "Desc")).block();
mongoRepository.save(
new Stock("MST", "Microsoft", "Desc")).block();
};
}
The mongoRepository.save() method is used to save the Stock document to ReactiveMongo. The block() method ensures that the save operation is completed before the next statement is executed.