Reactive MongoDB connector

As described previously in this chapter, Spring Data has excellent support for MongoDB. The Spring Data Reactive MongoDB module may be enabled with the spring-boot-starter-data-mongodb-reactive Spring Boot starter module. Reactive MongoDB support provides a reactive repository. The ReactiveMongoRepository interface defines the basic repository contract. The repository inherits all the features of ReactiveCrudRepository and adds support for QBE. Also, the MongoDB repository supports custom queries with the @Query annotation and additional query configuration with the @Meta annotation. The MongoDB repository supports query generation from a method name if it follows the naming convention.

Another distinct feature of the MongoDB repository is support for tailable cursors. By default, the database automatically closes a query cursor when all results are consumed. However, MongoDB has capped collections, which are fixed-size and support high-throughput operations. Document retrieval is based on the insertion order. Capped collections work similarly to circular buffers. Also, capped collections support a tailable cursor. This cursor remains open after the client consumes all results in the initial query and when someone inserts new documents into the capped collection, the tailable cursor will return the new documents. In ReactiveMongoRepository the method marked with the @Tailable annotation returns a tailable cursor represented by the Flux<Entity> type.

One level lower, the ReactiveMongoOperations interface and its implementation class, ReactiveMongoTemplategive more granular access to the MongoDB communication. Among other things, ReactiveMongoTemplate enables multi-document transactions with MongoDB. This feature works only for a non-sharded replica set with the WiredTiger storage engine. This capability is described in the Reactive transactions with MongoDB 4 section.

The reactive Spring Data MongoDB module is built on top of Reactive Streams MongoDB Driver, which implements the Reactive Stream specification and uses Project Reactor internally. In turn, MongoDB Reactive Streams Java Driver is built on top of MongoDB Async Java Driver. The How reactive repositories work section describes how ReactiveMongoRepository works in further detail.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.164.24