gpt4 book ai didi

java - Couchbase批量子文档操作

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:45:21 25 4
gpt4 key购买 nike

我正在使用 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 并继续,因此如果仅此而已,您的应用程序将退出。

如果您的应用被设计为异步使用输出,您可以只添加 subscribe 的一种变体。

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

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

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

关于java - Couchbase批量子文档操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54844006/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com