1

I am currently having this code to get Couchbase JsonDocument using the below code. I am trying to Migrate to Couchbase SDK3.2 and in 3.2 SDK Obseravable and JsonDocument is not being used. How can i use Flux to achieve the below code ?

        List<JsonDocument> foundDocs = Observable.from(campaignIdList)
                .flatMap(new Func1<String, Observable<JsonDocument>>() {
                    @Override
                    public Observable<JsonDocument> call(String id) {
                        return bucket.async().get(id);
                    }
                })
                .toList()
                .toBlocking()
                .single();
lkatiforis
  • 5,703
  • 2
  • 16
  • 35
  • This was also raised on the forums here https://forums.couchbase.com/t/how-to-get-jsondocument-using-couchbase-sdk-3-2/33915 – Graham Pople Jul 01 '22 at 10:58

1 Answers1

2

The most simplistic bulk fetch (without error handling or anything) looks like this:

Collection collection = scope.collection("campaigns");
ReactiveCollection reactiveCollection = collection.reactive();

//...

List<String> campaignIds = Arrays.asList("campaign_1", "campaign_2");
List<GetResult> results = Flux.fromIterable(campaignIds)
                              .flatMap(reactiveCollection::get)
                              .collectList()
                              .block();

Note that this is a blocking call and should not be used within a reactive pipeline.

You may find more samples here https://docs.couchbase.com/java-sdk/3.2/howtos/concurrent-async-apis.html

lkatiforis
  • 5,703
  • 2
  • 16
  • 35