From d2519eb059e4eb7252507faecb86926dc7f130c8 Mon Sep 17 00:00:00 2001 From: Christoph Strobl Date: Tue, 21 Nov 2017 15:23:40 +0100 Subject: [PATCH] DATAMONGO-1818 - Polishing. Move overlapping/duplicate documentation into one place. Original Pull Request: #512 --- .../reactive-mongo-repositories.adoc | 25 +++++++++++++++++-- .../asciidoc/reference/reactive-mongodb.adoc | 19 -------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/main/asciidoc/reference/reactive-mongo-repositories.adoc b/src/main/asciidoc/reference/reactive-mongo-repositories.adoc index c334f07d2..a9df36e07 100644 --- a/src/main/asciidoc/reference/reactive-mongo-repositories.adoc +++ b/src/main/asciidoc/reference/reactive-mongo-repositories.adoc @@ -190,12 +190,30 @@ public interface PersonRepository extends ReactiveMongoRepository stream = template.tail(query(where("name").is("Joe")), Person.class); + +Disposable subscription = stream.doOnNext(person -> System.out.println(person)).subscribe(); + +// … + +// Later: Dispose the subscription to close the stream +subscription.dispose(); +---- +==== + +Spring Data MongoDB Reactive repositories support infinite streams by annotating a query method with `@Tailable`. This works for methods returning `Flux` and other reactive types capable of emitting multiple elements. + +.Infinite Stream queries with ReactiveMongoRepository +==== [source,java] ---- @@ -215,3 +233,6 @@ Disposable subscription = stream.doOnNext(System.out::println).subscribe(); // Later: Dispose the subscription to close the stream subscription.dispose(); ---- +==== + +TIP: Capped collections can be created via `MongoOperations.createCollection`. Just provide the required `CollectionOptions.empty().capped()...` diff --git a/src/main/asciidoc/reference/reactive-mongodb.adoc b/src/main/asciidoc/reference/reactive-mongodb.adoc index 34a620852..cd59683db 100644 --- a/src/main/asciidoc/reference/reactive-mongodb.adoc +++ b/src/main/asciidoc/reference/reactive-mongodb.adoc @@ -457,25 +457,6 @@ NOTE: This example is meant to show the use of save, update and remove operation The query syntax used in the example is explained in more detail in the section <>. Additional documentation can be found in <> section. -[[mongo.reactive.tailcursors]] -== Infinite Streams - -By default, MongoDB will automatically close a cursor when the client exhausts all results supplied by the cursor. Closing a cursor on exhaustion turns a stream into a finite stream. For capped collections, you may use a https://docs.mongodb.com/manual/core/tailable-cursors/[Tailable Cursor] that remains open after the client consumes all initially returned data. Using tailable cursors with a reactive data types allows construction of infinite streams. A tailable cursor remains open until it's closed externally. It emits data as new documents arrive in a capped collection. - -Tailable cursors may become dead, or invalid, if either the query returns no match or the cursor returns the document at the "end" of the collection and then the application deletes that document. - -[source,java] ----- -Flux stream = template.tail(query(where("name").is("Joe")), Person.class); - -Disposable subscription = stream.doOnNext(person -> System.out.println(person)).subscribe(); - -// … - -// Later: Dispose the subscription to close the stream -subscription.dispose(); ----- - [[mongo.reactive.executioncallback]] == Execution callbacks