Uploaded image for project: 'Spring Data MongoDB'
  1. Spring Data MongoDB
  2. DATAMONGO-2545

Backwards incompatibilities on @Query

    XMLWordPrintable

    Details

      Description

      I posted this to /. but I think its actually a bug:

      https://stackoverflow.com/questions/61740106/moving-query-to-2-2-6
       
      I am moving our code to Spring Data MongoDB 2.2.6 from 2.1.X and am having some issues with some repository queries (that have worked in the past).

      One example:

       {{ @Query(
       " ?#{ hasRole('ROLE_ADMIN') ? {'_class': { '$eq' : 
       'region }} : { '$and' : { {'_class': { '$eq' : 'region' }}, {'$or': {{'users._id': 
       { '$oid' :principal.id}},{'usersFromHierarchy._id':{ '$oid' :principal.id}}} } } } } ")
       List<Region> findRegions();}}

      Doesn't get evaluated since the evaluation seems to expect a valid BSON document at the start of the query string. It only evaluates parameters.

      Another:

       {{@Query("{ 'name' : ?#{ hasRole('ROLE_ADMIN') ? '?0' : '?1' }}")
       Optional<TestObject> findByAuthName(String name, String name2);}}

      Doesn't work ... it always selects the first parameter.

      Looking at the code, seems like org.springframework.data.mongodb.util.json.ParameterBindingJsonReader is interpreting the ?#{..} as a parameter binding (line 369) and munging down to the first call param...

      Is there any guidance on this? What are the restrictions?

       

        Attachments

          Activity

            People

            Assignee:
            cstrobl Christoph Strobl
            Reporter:
            stevejerman Steve Jerman
            Last updater:
            Mark Paluch
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: