Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extra quotes being added to @Query

I have the following JSON structure:

{
  "communication": {
      "office": {
        "email": "[email protected]"
      },
      "private": {
        "email": "[email protected]"
      },
  }
}

I want to query dynamically for the email based on the type e.g. office or private. When I use the following command:

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

The

'communication.?0.email'

is converted to

'communication."office".email'

and mongo didn't find an entry. How can I avoid the quotes before and after office?

like image 973
Sebastian Avatar asked Apr 22 '15 15:04

Sebastian


People also ask

Is double quote allowed in SQL?

Double quotes generally aren't used in SQL, but that can vary from database to database. Stick to using single quotes.

Can I use double quotes in MySQL?

Double quotes are supported by MySQL for string values as well, but single quotes are more widely accepted by other RDBMS, so it is a good habit to use single quotes instead of double.


1 Answers

Simple answer is spring mongo doesn't supports what you are looking for. Why you are not passing everything as parameter rather as below.

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

where email value should

type= "communication." + type + ".email"
like image 88
sanjay patel Avatar answered Sep 28 '22 16:09

sanjay patel