我知道有一种方法可以使用Couchbase java sdk访问缩小的视图结果。我目前无法做的是使用spring-data访问简化视图。这可能吗?
视图:
View byIdGetDateStats = DefaultView.create("byIdGetDateStats",
"function (doc, meta) {"
+ "if(doc.docType == \"com.bd.idm.model.DayLog\"){"
+ " emit(doc.userid, doc.date)"
+" }}"
,"_stats"
);
当我尝试使用spring-data访问这样的视图时:
Query query = new Query();
query.setKey(ComplexKey.of(userid)).setReduce(true).setGroup(true);
ViewResult result = repo.findByIdGetDateStats(query);
错误消息
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.
...
答案 0 :(得分:1)
不,Spring-Data-Couchbase 1.x会始终将reduce
设置为false
。
如果您想使用简化视图并获取ViewResult
,请使用CouchbaseTemplate#queryView()
方法。
您仍然可以通过定义自定义存储库方法在存储库中执行此操作(请参阅此chapter of the doc,您应该可以在实现中调用getCouchbaseOperations
。)