hantsy / spring-reactive-sample

Spring 5/6 Reactive playground
https://hantsy.github.io/spring-reactive-sample/
GNU General Public License v3.0
1.32k stars 462 forks source link

spring-boot-starter-data-mongodb-reactive how to limit data #1

Closed comradeHsu closed 7 years ago

comradeHsu commented 7 years ago

I have a problem that is when i using spring-boot-starter-data-mongodb-reactive and it is a lot of data, but i can't return all data beacuse of too much.At this moment,i must be using limit,but i don't know how to limit,can you tell me or show me demo ? thanks!

hantsy commented 7 years ago

Check the docs of Reactor.

https://projectreactor.io/docs/core/release/api/reactor/core/publisher/Flux.html

prefetch is provied in reactor 3.0 and in 3.1 there are some methods archived this purpose, eg. skip and limitRate

hantsy commented 6 years ago

@knockinHeavenDoor Spring Data Mongo reactive supports Pageable as one of the method parameter in query execution as the original way, but it can only return a Flux instead of a Page result.

For simple pagination, use Flux take and skip directly.

hantsy commented 6 years ago

@knockinHeavenDoor Added pageable sample.

niksw7 commented 5 years ago

Since this is related to limit, is this functionality a bug in reactor-core:3.2.1.RELEASE?

Flux.range(1,1000).log()
            .limitRate(100,3)
            .subscribe()

This is the output returned. I was expecting request(3) to come post the fetch of 100 elements.

08:46:08.627 [main] INFO reactor.Flux.Range.1 - | request(100)
08:46:08.628 [main] INFO reactor.Flux.Range.1 - | onNext(1)
08:46:08.628 [main] INFO reactor.Flux.Range.1 - | onNext(2)
08:46:08.628 [main] INFO reactor.Flux.Range.1 - | onNext(3)
08:46:08.628 [main] INFO reactor.Flux.Range.1 - | request(3)
08:46:08.628 [main] INFO reactor.Flux.Range.1 - | onNext(4)
08:46:08.628 [main] INFO reactor.Flux.Range.1 - | onNext(5)
08:46:08.628 [main] INFO reactor.Flux.Range.1 - | onNext(6)
08:46:08.628 [main] INFO reactor.Flux.Range.1 - | request(3)
08:46:08.629 [main] INFO reactor.Flux.Range.1 - | onNext(7)
08:46:08.629 [main] INFO reactor.Flux.Range.1 - | onNext(8)
08:46:08.629 [main] INFO reactor.Flux.Range.1 - | onNext(9)