Seb*_*ian 7 spring-data spring-data-mongodb
我有以下JSON结构:
{
"communication": {
"office": {
"email": "test@example.com"
},
"private": {
"email": "test2@example.com"
},
}
}
Run Code Online (Sandbox Code Playgroud)
我想基于类型(例如办公室或私人)动态查询电子邮件.当我使用以下命令时:
@Query(value = "{ 'communication.?0.email' : ?1 }")
Object findByEmail(String type, String email);
Run Code Online (Sandbox Code Playgroud)
该
'communication.?0.email'
Run Code Online (Sandbox Code Playgroud)
转换为
'communication."office".email'
Run Code Online (Sandbox Code Playgroud)
和mongo没有找到一个条目.如何在办公前后避免报价?
简单的答案是 spring mongo 不支持您正在寻找的内容。为什么您不将所有内容作为参数传递,而不是如下所示。
@Query(value = "{ '通讯.?0.email' : ?1 }") Object findByEmail(String type, String email);
电子邮件值应该在哪里
type= "communication." + type + ".email"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
425 次 |
| 最近记录: |