3

I am using Couchbase-Java SDK 2.7.1 and trying to perform bulk subdoc operation on the set of document keys. The below code is not throwing any error but the documents aren't getting updated after the execution of the given code.

/*
   Document structure:
   {
       "key1": "",
       "key2:: ""
   }
*/

List<String> docIds = new ArrayList<String>();
docIds.add("mydoc-1");
docIds.add("mydoc-2");
String docPath = "key1";
String value = "myVal";

Observable<String> docIdsObs = Observable.from(docIds);
Observable<DocumentFragment<Mutation>>
    subdocAppendObs = 
      docIdsObs.flatMap(docId -> this.subdocUpsert(bucket, docId, docPath, value,
                                                  persist, replicate, timeout,
                                                  timeunit));
dnault
  • 8,340
  • 1
  • 34
  • 53
Ashwin
  • 993
  • 1
  • 16
  • 41

1 Answers1

1

As dnault suggested in a comment, you aren't ever triggering the Observable to actually start operations. Execution flow will set up the Observable and continue, so your app will just exit if that's all there is to it.

If you're app is designed to consume the output asynchronously, you can just add one of the variants of subscribe.

If you want to block until the operations are complete, you'd want to use a countdown latch, or you can do something like

    List<DocumentFragment<Mutation>> result = docIdsObs.flatMap(docId -> this.subdocUpsert(bucket, docId, docPath, value,
                                                  persist, replicate, timeout,
                                                  timeunit));
        .toList()
        .toBlocking()
        .single();

That will block and produce all the results in a single list.

Hod
  • 2,236
  • 1
  • 14
  • 22