Hello,
What is the purpose of createDocument()
flag in Subdoc API? It’s very little documented but the name suggests that the document should be created (when it doesn’t exist). However, when I tried to use it I’m getting quite strange/buggy behaviour. The following test:
public class CouchbaseTest
{
CouchbaseCluster cluster = CouchbaseCluster.create(DefaultCouchbaseEnvironment.builder().build());
Bucket bucket = cluster.openBucket("default");
@Test
public void shouldCreateDocument()
{
bucket.mutateIn("doc1") //
.createDocument(true) //
.upsert("prop1", "abc")//
.upsert("prop2", "def")//
.execute();
}
}
Results in:
com.couchbase.client.core.CouchbaseException: INVALID_ARGUMENTS
at com.couchbase.client.java.subdoc.SubdocHelper.commonSubdocErrors(SubdocHelper.java:100)
at com.couchbase.client.java.subdoc.AsyncMutateInBuilder$2.call(AsyncMutateInBuilder.java:1092)
at com.couchbase.client.java.subdoc.AsyncMutateInBuilder$2.call(AsyncMutateInBuilder.java:1050)
at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:69)
What’s interesting, if trying to upsert only one property:
bucket.mutateIn("doc1") //
.createDocument(true) //
.upsert("prop1", "abc")//
.execute();
The exception thrown is:
com.couchbase.client.java.error.DocumentDoesNotExistException: Document not found for subdoc API: doc1
at com.couchbase.client.java.subdoc.SubdocHelper.commonSubdocErrors(SubdocHelper.java:64)
at com.couchbase.client.java.subdoc.AsyncMutateInBuilder$6.call(AsyncMutateInBuilder.java:1162)
at com.couchbase.client.java.subdoc.AsyncMutateInBuilder$6.call(AsyncMutateInBuilder.java:1149)
Tested with:
- Couchbase 4.5.1-2844 Community Edition (build-2844)
- com.couchbase.client:java-client:2.4.6
Another interesting thing is that when the above test are run with https://github.com/couchbase/CouchbaseMock everything seems to work fine !
Regards,
Adam