Added extra quotes in @Query

I have the following JSON structure:

{ "communication": { "office": { "email": " test@example.com " }, "private": { "email": " test2@example.com " }, } } 

I want to dynamically request emails based on type, for example. office or private. When I use the following command:

 @Query(value = "{ 'communication.?0.email' : ?1 }") Object findByEmail(String type, String email); 

 'communication.?0.email' 

converted to

 'communication."office".email' 

and mongo did not find the record. How to avoid quotes before and after office?

+5
source share
1 answer

The simple answer spring mongo does not support what you are looking for. Why do not you pass everything as a parameter, and not as below.

@Query (value = "{'communication.?0.email' :? 1}") Object findByEmail (String type, String email);

where the email value should

 type= "communication." + type + ".email" 
+1
source

All Articles