Using MongoDB reactive repository

To use the reactive data access for MongoDB instead of its synchronous counterpart, we have to add the following dependency to our Gradle project:

compile 'org.springframework.boot:spring-boot-starter-data-mongodb-reactive'

Let's say we want to refactor our simple MongoDB application from the previous section to become reactive. In this case, we may leave the Book entity as is, without making any modifications. All the annotations associated with MongoDB Object-Document Mapping are the same for both synchronous and reactive MongoDB modules. However, in the repository, we now have to replace ordinary types with reactive types:

public interface ReactiveSpringDataMongoBookRepository
   extends ReactiveMongoRepository ...

Get Hands-On Reactive Programming in Spring 5 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.