I know there is a way to access reduced view results using the Couchbase java sdk. What I am currently unable to do is use spring-data to access the reduced view. Is this possible?
view:
View byIdGetDateStats = DefaultView.create("byIdGetDateStats",
"function (doc, meta) {"
+ "if(doc.docType == \"com.bd.idm.model.DayLog\"){"
+ " emit(doc.userid, doc.date)"
+" }}"
,"_stats"
);
When I attempt to use spring-data to access the view like this:
Query query = new Query();
query.setKey(ComplexKey.of(userid)).setReduce(true).setGroup(true);
ViewResult result = repo.findByIdGetDateStats(query);
Error Message
java.lang.IllegalStateException: Failed to execute CommandLineRunner
...
Caused by: java.lang.RuntimeException: Failed to access the view
...
Caused by: java.util.concurrent.ExecutionException: OperationException: SERVER: query_parse_error Reason: Invalid URL parameter 'group' or 'group_level' for non-reduce view.
....
Caused by: com.couchbase.client.protocol.views.ViewException: query_parse_error Reason: Invalid URL parameter 'group' or 'group_level' for non-reduce view.
....
No, Spring-Data-Couchbase 1.x will always set reduce
to false
.
If you want to use a reduced view and get the ViewResult
, use the CouchbaseTemplate#queryView()
method.
You can still do so in a repository by defining custom repository method (see this chapter of the doc, you should be able to call getCouchbaseOperations
in your implementation).