Couchbase批量子文档操作

问题描述 投票:3回答:1

我正在使用Couchbase-Java SDK 2.7.1并尝试对文档密钥集执行批量子网操作。下面的代码没有抛出任何错误,但在执行给定代码后文档没有得到更新。

/*
   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));
java rx-java couchbase subdocument couchbase-java-api
1个回答
1
投票

正如dnault在评论中所说,你并没有触发Observable实际开始运营。执行流程将设置Observable并继续,所以你的应用程序将退出,如果这就是它的全部。

如果您的应用程序旨在异步使用输出,则可以添加subscribe的一个变体。

如果你想阻止操作完成,你想要使用倒计时锁存器,或者你可以做类似的事情

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

这将阻止并在单个列表中生成所有结果。

© www.soinside.com 2019 - 2024. All rights reserved.