在 couchbase 中,考虑一个文档有一个字段,其中包含一组引用其他文档的键
{
"some_ids": ["otherdoc1", "otherdoc2", "otherdoc3"]
}
这两种用于检索 some_ids
字段中所有文档的解决方案中哪一种提供最佳性能?
-
List<JsonDocument> foundDocs = Observable .just("otherdoc1", "otherdoc2", "otherdoc3") .flatMap(new Func1<String, Observable<JsonDocument>>() { @Override public Observable<JsonDocument> call(String id) { return bucket.async().get(id); } }) .toList() .toBlocking() .single();
创建一个设计 View ,然后使用
startKey
和endKey
检索其索引的子集// Map function function(doc, meta) { if (doc.type == 'otherdoc') { emit(meta.id, doc); } } // ViewQuery (in a java method) ViewQuery.from('designOther', 'viewOther') .startKey('otherdoc1') .endKey('otherdoc2');
最佳答案
在 Couchbase 中,当您知道 key 时,SDK 就知道向哪个节点请求该 key (通过散列)。另一方面,查询 View 意味着 View 引擎联系集群中的每个节点。
因此,在 RxJava 中直接 get && 批处理,因为您知道 key ,将为您节省额外的往返次数,并且最终应该获得更好的性能!
关于java - Couchbase 在 Java 中批量检索多个 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28306642/