Is it possible to use named parameters for a @Query method in a mongodb repository, just like we can do with a jpa repository (http://docs.spring.io/spring-data/jpa/docs/1.4.3.RELEASE/reference/html/jpa.repositories.html section 2.3.5)?
As an example, I would like to use the following code:
@Query("{'store' : :store, 'app' : :app }")
List<T> findByStoreAndApp(@Param("store") String store, @Param("app") String app);
instead of:
@Query("{'store' : ?0, 'app' : ?1 }")
List<T> findByStoreAndApp(String store, String app);
It is possible, try:
@Query("{'store' : :#{#store}, 'app' : :#{#app} }")
List<T> findByStoreAndApp(@Param("store") String store, @Param("app") String app);
The support of SpEL expressions in @Query was introduced in Spring Data MongoDB 1.8.
https://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#mongo.aggregation.projection.expressions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With