我想从Couchbase存储桶中获取某种类型的所有文档。
我创建了一个扩展了CatRepository
的{{1}},所以我继承了CouchbaseRepository
方法。
运行程序并到达以下行:
findAll()
我收到以下错误:
Iterable<Cat> all = catRepository.findAll();
这是存储库(否)代码:
Servlet.service() for servlet [dispatcherServlet] in context with path []
threw exception [Request processing failed; nested exception is
org.springframework.dao.InvalidDataAccessResourceUsageException: View cat/all does not exist.; nested exception is
com.couchbase.client.java.error.ViewDoesNotExistException: View cat/all does not exist.] with root cause
rx.exceptions.OnErrorThrowable$OnNextValue: OnError while emitting onNext
value: com.couchbase.client.java.document.json.JsonObject.class
at rx.exceptions.OnErrorThrowable.addValueAsLastCause(OnErrorThrowable.java:118) ~[rxjava-1.2.7.jar:1.2.7]
at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:73) ~[rxjava-1.2.7.jar:1.2.7]
at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:77) ~[rxjava-1.2.7.jar:1.2.7]
at rx.internal.producers.SingleProducer.request(SingleProducer.java:65) ~[rxjava-1.2.7.jar:1.2.7]
at rx.Subscriber.setProducer(Subscriber.java:211) ~[rxjava-1.2.7.jar:1.2.7]
at rx.internal.operators.OnSubscribeMap$MapSubscriber.setProducer(OnSubscribeMap.java:102) ~[rxjava-1.2.7.jar:1.2.7]
at rx.internal.operators.OnSubscribeMap$MapSubscriber.setProducer(OnSubscribeMap.java:102) ~[rxjava-1.2.7.jar:1.2.7]
at rx.internal.operators.OperatorSingle$ParentSubscriber.onCompleted(OperatorSingle.java:113) ~[rxjava-1.2.7.jar:1.2.7]
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.checkTerminated(OperatorObserveOn.java:281) ~[rxjava-1.2.7.jar:1.2.7]
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.call(OperatorObserveOn.java:216) ~[rxjava-1.2.7.jar:1.2.7]
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55) ~[rxjava-1.2.7.jar:1.2.7]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[na:1.8.0_161]
at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266) ~[na:1.8.0_161]
at java.util.concurrent.FutureTask.run(FutureTask.java) ~[na:1.8.0_161]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) ~[na:1.8.0_161]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) ~[na:1.8.0_161]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_161]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_161]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_161]
答案 0 :(得分:0)
findAll
需要在Couchbase本身上创建视图。
您可以通过Couchbase UI执行此操作:
all
,因此文档称为_design/[bucket_name]/foo
并视图all
function (doc, meta) {
if (doc._class == "[your_package].Foo") {
emit(meta.id, null);
}
}
注意:此答案与Couchbase 6有关。此过程在旧版本/新版本上可能会有所不同
答案 1 :(得分:0)
您还可以按如下方式使用注释@ViewIndexed:
@N1qlPrimaryIndexed
@ViewIndexed(designDoc = "area")
public interface AreaRepository extends CouchbaseRepository<Area, String> {
List<Area> findByBusinessUnityIdAndRemoved(String businessId, boolean removed);
}