Hi,
I’m trying to do a bulck update using java sdk.I’m using java-client 2.4.3.
I’m trying the following approch:
-Get documents using N1ql
-Update the retrieved document in asynchrnonous way.
Her is my code:
Statement statement = select(bucketName + “.*,meta().id as docKey”).from(bucketName).where(“_type=‘Product’”).limit(1);
N1qlQuery n1qlQuery=N1qlQuery.simple(statement);
startTime=System.currentTimeMillis();
bucket.async() //switch to asyn API
.query(n1qlQuery)
.timeout(20, TimeUnit.SECONDS) //global timeout for the query
.flatMap(result → result.rows()).map(new Func1<AsyncN1qlQueryRow, Observable<JsonDocument>>() {
@Override public Observable<JsonDocument> call(AsyncN1qlQueryRow docToUpdate) { String docKey=docToUpdate.value().getString("docKey"); docToUpdate.value().put("myfield", JsonArray.fromJson(jsonString)); JsonObject obj=docToUpdate.value().removeKey("docKey"); JsonDocument doc = JsonDocument.create(docKey, obj); //bucket.upsert(doc); System.out.println("Updating "+docKey); return bucket.async().upsert(doc); } }).last().toBlocking().single();
The problem is that the updates isn’t happening , but if I uncomment the expression bucket.upsert(doc) than the update works.
Is there any thing rong within my code?
Another question please, I know that the new versions supportes partial/subdocument update.Can this be done also in batch/asynchnous?
Thanks