繁体   English   中英

Couchbase批量子文档操作

[英]Couchbase bulk subdocument operation

我正在使用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));

正如dnault在评论中所建议的那样,你并没有触发Observable实际开始操作。 执行流程将设置Observable并继续,因此如果完全存在,您的应用程序将退出。

如果您的app设计为异步使用输出,则只需添加subscribe一个变体即可。

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM