Bulk update issue

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);
bucket.async() //switch to asyn API
.timeout(20, TimeUnit.SECONDS) //global timeout for the query
.flatMap(result -> result.rows())

  .map(new Func1<AsyncN1qlQueryRow, Observable<JsonDocument>>() {
  	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);
  		 System.out.println("Updating "+docKey);
  		 return bucket.async().upsert(doc);

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?


@zizou I think I know whats wrong with your code. Instead of using Map you actually need to use flatMap here. In your case you are returning an observable which you never consume, so its not run at all I think.

So instead of .map after the .flatMap you need to chain in another .flatMap doing basically the same thing but your type signature changes a little bit.

On your second question yes, you can do subdocument upsert also asynchronously like you are working here with a full document.