Bulk read and write using N1QL vs get/upsert


#1

I want to do bulk read and bulk insert using couchbase. I have used below code:
BULK READ
List guidDocList = Observable
.from(ids)
.flatMap(new Func1<String, Observable>() {
@Override
public Observable call(String id) {
return dsBucket.async().get(id );
}
})
.toList()
.toBlocking()
.single();

BULK INSERT
Observable
.from(doc1List)
.flatMap(new Func1<SerializableDocument, Observable>() {
@Override
public Observable call(final SerializableDocument docToInsert) {
return dsBucket.async().upsert(docToInsert);
}
})
.last()
.toBlocking()
.single();

I have been asked to use N1QL for both bulk read and insert. Can you plz give me an example for both and also let me know which one is better(above which i given or using N1QL)?

Thanks in advance.


#2

BULK READ (given as set of ID’s):

SELECT *
FROM dsBucket USE KEYS [ id1, id2, ... ];

BULK INSERT (given a set of docs):

INSERT INTO dsBucket
(KEY, VALUE)
VALUES (key1, doc1), (key2, doc2), ...;

You can also use UPSERT instead of INSERT.


#3

Many Thanks Gerald,

Can you please point out any link with working example of above code. And also i need to know which approach is better in terms of performance(the one which I gave in question or the one which you pointed out).

Thanks in advance.


#4

For performance, you need to measure both approaches with your own data set and environment.

For examples, here are a few suggestions:

Free online learning: http://training.couchbase.com/online#

Sample app: http://try.couchbase.com/#/login

Code samples: http://www.couchbase.com/get-started-developing-nosql#See_Some_Code_Samples

Please let us know how these links work for you.

Thanks,
Gerald