In Couchbase SDK 3.0 can we fetch raw JsonObject using JPA

Hi All,

I have the use case in spring JPA method where I need to fetch the raw JsonObject based on document ids. I tried below repository class but it doesn’t work for me. Please help me on it.

public interface MyCouchbaseRepository extends ReactiveSortingRepository<JsonObject, String> {
Flux findAllById(List documentIds);


but it doesn’t work for me

It would be helpful to know what “doesn’t work” means in this case. Does it not compile? Does application initialization fail? Does the query execution fail? does it return the wrong objects?

Also - are you using Spring Data JPA or Spring Data Couchbase? Seems you would need to be using Spring Data Couchbase.

When I try this out, saving the object fails because spring-data-couchbase does not know what to use for the key. (repository entities must have a field annotated with @Id or a field named ‘id’). JsonObject has neither. While this prevents saving with spring data couchbase, it does not prevent (attempting) to read. However, since spring-data-couchbase does not have any mapping of the properties in the document to JsonObject (JsonObject only has ‘content’), it simply produces an empty JsonObject.

If you want to obtain JsonObjects, just use the Couchbase SDK directly…

JsonObject jo = couchbaseTemplate.getCouchbaseClientFactory().getDefaultCollection().get(id).contentAsObject();

btw - the base interface for a reactive couchbase repository is

public interface MyCouchbaseRepository extends ReactiveCouchbaseRepository<MyEntityClass, String>