regexspring-bootspring-data-mongodbquotesmql

Spring data mongo @Query with / or $regex add quotes


I am using spring boot with spring data mongo and @Query to carry out a regex expression query also using spell.

In my documents I have something like this

enter image description here

I want to be able to filter also by a predictive string depending on the language (don't worry about languages my main problem is in the regex)

@Query(
      "{$and: [ ?#{ ([6] == null) ? { $expr : 'true'} : { 'translations' : {$elemMatch: { 'language' : [7], 'description' : {$regex : [6]} } } }}]}")
  public List<MyObject> findByCatalog(
      String predictive,
      String locale);

The main problem is that the regex does not work because I am adding to the predictive string // and it is adding extra quotes that always return me nothing.

There is any solution? I have tried different things and I am desperate, please avoid saying change to mongo template because actually the query is bigger than that.

Thanks in advance


Solution

  • The solution was tu use .. instead of // and it works perfect