Reputation: 156
In couchbase, consider a document has a field which contains a set of keys referencing other documents
{
"some_ids": ["otherdoc1", "otherdoc2", "otherdoc3"]
}
Which one of these 2 solutions for retrieving all doc in some_ids
field gives the best performance?
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();
Create a design view, then retrieve a subset of its index with startKey
and 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');
Upvotes: 2
Views: 1784
Reputation: 28301
in Couchbase, when you know the key, the SDK knows which node to ask for that key (through hashing). On the other hand, querying a view implies the view engine to contact every node in the cluster.
So direct get && batching in RxJava, since you know the key(s), will save you additional round-trips and should end up the better performer!
Upvotes: 2