【问题标题】:Couchbase bulk subdocument operationCouchbase 批量子文档操作
【发布时间】:2019-07-17 13:07:18
【问题描述】:

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

/*
   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));

【问题讨论】:

  • 一个Observable 通常在你subscribe 之前不会做任何工作。

标签: java rx-java couchbase subdocument couchbase-java-api


【解决方案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();

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

【讨论】:

    猜你喜欢
    • 2019-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多