我有以下 JSON 结构:
{
"communication": {
"office": {
"email": "test@example.com"
},
"private": {
"email": "test2@example.com"
},
}
}
我想根据类型动态查询电子邮件,例如办公室或私有(private)。当我使用以下命令时:
@Query(value = "{ 'communication.?0.email' : ?1 }")
Object findByEmail(String type, String email);
这
'communication.?0.email'
被转换为
'communication."office".email'
mongo 没有找到条目。如何避免上类前后的报价?
最佳答案
简单的答案是 spring mongo 不支持您正在寻找的内容。为什么您不将所有内容都作为参数传递,而不是如下所示。
@Query(value = "{ 'communication.?0.email' : ?1 }")
Object findByEmail(String type, String email);
电子邮件值应该在哪里
type= "communication." + type + ".email"
关于spring-data - 额外的引号被添加到 @Query,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29802111/