Error when try to use newest strutures (List, Set, Map, Queue)

When I try to use a special structure I had some issues:

When the key does not exist and I use append list:

bucket.listAppend("mykey", object);

Then it returns an exception

com.couchbase.client.java.error.DocumentDoesNotExistException: Document not found for subdoc API: mykey

When I created the key before:

bucket.insert(JsonDocument.create("mykey"));

And then do the append on the list

bucket.listAppend("mykey", object);

It returns a NPE:

cause: rx.exceptions.OnErrorThrowable$OnNextValue: OnError while emitting onNext value: java.util.ArrayList.class

This same error happened also on Set, Map and Queue. Also when I try to use just either String or a complex object.

My version:

  <dependency>
            <groupId>com.couchbase.client</groupId>
            <artifactId>java-client</artifactId>
            <version>2.4.1</version>
        </dependency>

My server version:
Version: 4.5.1-2844 Enterprise Edition (build-2844)

Hi @otaviopolianasantana,

The underlying document is different for each data structure, list uses JsonArrayDocument. It is more straightforward to create the document using datastructures api
ctx.bucket().listAppend(“mykey”, “”, MutationOptionBuilder.builder().createDocument(true));

I couldn’t reproduce the exact error, you are seeing but,

bucket.insert(JsonDocument.create(“mykey”));
bucket.listAppend(“mykey”, “foo”);

throws DocumentNotJsonException which is valid because the first line creates a document which is null.

bucket.insert(JsonDocument.create("mykey", JsonObject.create())); bucket.listAppend("mykey", "foo"); will throw SUBDOC_PATH_MISMATCH as it tries append to {} instead of an array bucket.insert(JsonArrayDocument.create("mykey", JsonArray.create()); bucket.listAppend("mykey", "foo"); This should work

Thanks, that works on List.
Do you know where on documentation has this information?
Or can you give the document type to the others structures (Set, Map, Queue)?

Thanks

That information is not exposed on the bucket-level datastructure operations, collections api would expose those http://docs.couchbase.com/sdk-api/couchbase-java-client-2.4.1/com/couchbase/client/java/datastructures/collections/CouchbaseArrayList.html.

Using MutationOptionBuilder createDocument takes care of it when using bucket operations.

bucket.listAppend(“mykey”, “”, MutationOptionBuilder.builder().createDocument(true))

http://docs.couchbase.com/sdk-api/couchbase-java-client-2.4.1/com/couchbase/client/java/datastructures/MutationOptionBuilder.html

Thanks that’s working :slight_smile:

1 Like