Initialising stock data using the Command Line Runner

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 ...

Get Mastering Spring 5.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.