1
votes

I'm developing a stream with webflux from a mongodb collection with spring boot and spring data mongodb with tailable cursors.

The stream is working when the collection has 1 document or more due to you can get the cursor. The issue is that I want to open the stream with an empty collection, since I want to stream every document in the collection.

I've been reading the docs and it's supposed to be correct:

https://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#tailable-cursors

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 the application then deletes that document

I'm evaluating the best way to achieve this (open the stream from an empty collection) with spring boot and flux but I would rather to know if there is some idea or workaround.

Thank you.

1

1 Answers

1
votes

Indeed, even "find all" on empty capped collections is considered as no match and the cursor is dead. reactiveMongoOperations.tail(new Query(), Event.class) returns a dead cursor, so does the annotated repository flavor. Spring docs just duplicate mongo docs, which state

Tailable cursors may become dead, or invalid, if either: the query returns no match. the cursor returns the document at the “end” of the collection and then the application > deletes that document.

Only workaround seems to be an initial dummy entry inserted prior subscription.