AsyncMutateInBuilder with upsertDocument flag couldn't remove properties


During work with AsyncMutateInBuilder I noticed a problem:

  • when AsyncMutateInBuilder has set upsertDocument flag to true, usage of asyncMutateInBuilder.remove in not possible and result in:
Caused by: com.couchbase.client.core.CouchbaseException: INVALID_ARGUMENTS
	at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(
	... 18 more

Sample to reproduce:

final AsyncMutateInBuilder asyncMutateInBuilder = asyncBucket
final SubdocOptionsBuilder optionsBuilder = SubdocOptionsBuilder.builder().createPath(true);
asyncMutateInBuilder.upsert(pathToUpsert, newValue, optionsBuilder);

When I commented insertDocument flag it is working as expected.
Unfortunately I need add and remove some fields in one run + if document doesn’t exist yet create it.

Could you take a look on it? I don’t think that it is expected behaviour upsertDocument flag shouldn’t forbid removing some document paths.

Couchabse server version: docker couchbase:community-6.0.0
Couchbase Java SDK:

compile group: 'com.couchbase.client', name: 'java-client', version: '2.7.2'

Hey @sebarys

You’re using insertDocument rather than upsertDocument in that example. So you’re trying to insert a new document, while also removing an existing field. That combo doesn’t make sense, which is why the call fails. Hope that makes sense.

Hi @graham.pople, thanks for reply!
Yeah, it is typo but it doesn’t matter you can use either insertDocument or upsertDocument flag and result is the same.

I would like to perform some operations on document and if it doesn’t exist create it. By using upsertDocument or insertDocument flag I don’t need to check if document exist before any operation, otherwise I would need make extra call before any interaction with the document .

It wouldn’t make sense if I would like to use only asyncMutateInBuilder.remove with that flag, but for case when I want update one part of document and remove other if exists how could I do it differently when I need keep in mind that this operation could be the first interaction with this document?

@graham.pople hope that my comment clarify a bit context and now you see valid use case for such operation