Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Couchbase bulk subdocument operation

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));
like image 698
Ashwin Avatar asked Nov 28 '25 03:11

Ashwin


1 Answers

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.

like image 82
Hod Avatar answered Nov 29 '25 17:11

Hod