Sub-doc API - upsert auto-create document?

@matt.carabine, @drigby, thanks a lot for your help!

Catching exception on new doc upsert sounds good, however its somewhat tricky when I do batch of such upsert operations via Observables in async API… Maybe I have to study Observables more, at the moment I don’t know how to chain different try-retry operations without creating some temp variables to track failed items. Is there any example in documentation for such batch chain?
Anyway, great to hear that 5.0 simplifies this process!

Here is example - how do I do retry?

 Observable.just("user:99999999991", "user:99999999992")
                .flatMap(key -> bucket.async().mutateIn(key).upsert("age", 42, true).execute())
                .onErrorResumeNext(error -> {
                    System.out.println(error);
                    // I would like to do code below - but I don't have document key here...
                    // nor it is possible to extract key from DocumentDoesNotExistException
                    return null;
                    //JsonObject json = JsonObject.empty();
                    //json.put("age", 42);
                    //return bucket.async().upsert(JsonDocument.create(key, json));
                })
                .toBlocking()
                .subscribe();

As I’ve mentioned in the code comments, there is no way to get key of failed document.
And even documentation https://developer.couchbase.com/documentation/server/current/sdk/java/async-programming.html in Error Handling section onErrorResumeNext sample uses hardcoded “id” in onErrorResumeNext… however this makes such function not usable for flatMap.
I guess, proper way would be to extract failed document id from exception, but I didn’t find how to do that.

As for tags, the problem with retry is that I add several tags in one operation - and if even one of them already exists, it will throw exception for arrayAddUnique but I can’t ignore it, because there are other tags in array which I planned to add… if there was “hashsetAdd” method, it would solve this problem )

Thank you!