java - 按内部对象字段查询
问题描述
我有一个相当微不足道的问题,但我经常遇到错误。
所以我有一个Request
包含列表字段的类calls
。而且我想使用 Mongo 通过 -object 的to
-field查询请求Call
(例如,查找包含至少一个对 person 的调用的所有请求Alice
)。
@Document
public class Request {
@Id
String id;
String content;
List<Call> calls;
//getters setters etc.
}
public class Call {
String from;
String to;
DateTime timestamp;
//getters setters etc.
}
在我的存储库中,我尝试执行不同类型的查询。但它们都返回错误。
interface RequestRepo extends ReactiveMongoRepository<Request, String> {
@Query("select r from Request r where r.calls.to = :userId")
// I also tried "@Query({ 'calls.to' : ?0 }")
Flux<Request> findAllByCallTo(@Param("userId") String userId);
}
但不幸的是我总是得到一个错误:
readStartDocument can only be called when CurrentBSONType is DOCUMENT, not when CurrentBSONType is STRING.
可能是什么问题以及编写查询的正确方法是什么?
解决方案
推荐阅读
- android - 更改 sqlite 数据库的名称
- javascript - 将数字设置为 json 对象的类
- javascript - 如何在画布中获得更多光标位置
- javascript - 从 Vue 中的(未知深度)多维对象渲染列表
- arrays - React - 将数组值从箭头函数传递到另一个 .js 文件
- java - 使用 Java SDK 将 Quicktime 视频上传到 S3
- javascript - ExpectedConditions 在量角器中抛出错误
- r - R ifelse 更改整个数据帧的值格式
- java - SwaggerUI - 自定义 URL 基本路径
- java - 所需库的存档:无法读取项目“XYZ”中的“lib/Chrome/chromedriver”或者不是使用 ChromeDriver Selenium Java 的有效 ZIP 文件