简体   繁体   English

如何一次查询多个条目

[英]How to query multiple entries at once

I am using spring boot reactive and Couchbase我正在使用 spring 引导反应和 Couchbase

Flux<Item> findByLocation_LocationIdOrderByCreatedAtDesc(String locationId);

Just to point here I am accessing Location.locationId.只是指出这里我正在访问 Location.locationId。 Location object has locationId field in main document位置 object 在主文档中有 locationId 字段

Also below properties is not printing the generated Couchbase query, if anyone can help with that too,如果有人也可以提供帮助,下面的属性也不会打印生成的 Couchbase 查询,

logging: level: org.springframework.data: DEBUG日志记录:级别:org.springframework.data:调试

The response is fine when database has only one entry, but when the db has more than one entry matching criteria it throws "Source emitted more than one item".当数据库只有一个条目时响应很好,但是当数据库有多个条目匹配条件时,它会抛出“源发出多个项目”。

My controller is returning我的 controller 回来了

Flux<Item>

Following two annotations are mandatory or it keep returning the exception以下两个注释是强制性的,否则它会不断返回异常

@N1qlPrimaryIndexed @ViewIndexed @N1qlPrimaryIndexed @ViewIndexed

@Ghrissology I already had ReactiveCouchbaseRepository @Ghrissology 我已经有了 ReactiveCouchbaseRepository

Normally, the spring Data change the query based on the return type.通常,spring 数据会根据返回类型更改查询。 if you want one result it use getSingleResult() automatically:如果你想要一个结果,它会自动使用 getSingleResult() :

Item findByLocation_LocationIdOrderByCreatedAtDesc(String locationId);

in you case, i think he didn't understand the return type because you didn't implement a ReactiveCrudRepository:在你的情况下,我认为他不理解返回类型,因为你没有实现 ReactiveCrudRepository:

public interface ReactiveItemRepository
  extends ReactiveCrudRepository<item, String> {}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM