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

Add support for restricting results by document types in the @Query annotation

    XMLWordPrintable

Details

    • New Feature
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 2.0.12 (Kay SR12)
    • None
    • Core

    Description

      Since https://github.com/spring-projects/spring-data-mongodb/pull/53, it is now possible to  restrict results of a query to specific types, thanks to the new 'restrict ()' method on the Query object.

      it would be nice if this feature could be made available on the @Query annotation as well.

      This could be done, for example, via a restrict parameter that would accept a array of Class<?>, just like the restrict method on the Query class.

      For example:

      @Query(restrict={BaseDoc.class, SpecialDoc1.class, SpecialDoc2.class})
      BaseDoc findBySomething();
      

       

      Of course i could also use:

      @Query(" '_class': {'$in': ['com.mydomain.BaseDoc', 'com.mydomain.SpecialDoc1', 'com.mydomain.SpecialDoc2']}")
      BaseDoc findBySomething();
      

       
      to do the job, but i'm looking for a more typesafe approach. Beside i would like to still be able to use the query method mechanism to generate the actual query.

       

      Attachments

        Activity

          People

            olivergierke Oliver Drotbohm
            tinesoft tinesoft
            Spring Issues Spring Issues
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: