2

What is the recommended way to iterate over a large result with reactive mongo template?

I can't find a reactive alternative for the blocking MongoTemplate::stream() operation, which uses MongoDB cursor (and works perfectly well).

When I do the most obvious thing with Reactive template, my app works for a while, and then just stuck without any exceptions (Kotlin snippet below):

/* Repository */

fun findByStatus(status: Status): Flux<Event>

/* Service */

repository.findByStatus(status).buffer(1000).collect { events ->
       // process batch of events
}

I don't understand - if it tries to fetch all the results in memory, it should fail with OOM right away, but not stuck some time later, right?

What am I doing wrong?

Brian Clozel
  • 56,583
  • 15
  • 167
  • 176
silent-box
  • 1,649
  • 3
  • 21
  • 40

0 Answers0