Closed spring-projects-issues closed 5 years ago
Oliver Drotbohm commented
I'm a bit hesitant to extend the semantics of a Pageable
into the field spec area as field specs absolutely don't correlate to pagination at all. So what you're generally trying to achieve is to be able to pass field specs to query methods dynamically, right? You might want to watch issue DATAMONGO-103 for a Querydsl based approach to that but we probably add a general purpose mechanism to dynamically hand field specs to query methods. I thought of something alongside
public UserRepository extends Repository<User, Long> {
List<User> findByFirstname(String firstname, @FieldSpec DBObject spec);
}
We might support DBObject
, Collection
instances or plain arrays and varags for the @FieldSpec
annotation. We could also add special CRUD methods to MongoRepository
interface for findAll
and findOne
overloads although these methods can actually be added to the repository interface as needed by declaring an empty @Query
annotation once the general infrastructure is in place.
public UserRepository extends Repository<User, Long> {
@Query("{}")
List<User> findAll(@FieldSpec DBObject spec);
}
What do you think?
Robert Stiller commented
The QueryDSL approch sounds good - but QueryDSL is needed, which would be a little bit invasiv...
I would prefer a simple array/list of Strings or a org.springframework.data.mongodb.query.Field object
Mark Paluch commented
That's available via the @Field
annotation (see reference documentation) and interface projections
Robert Stiller opened DATAMONGO-184 and commented
It would be helpful to have the option for field-selection using a
org.springframework.data.domain.Pageable
.I guess the best way to do it is to extend
org.springframework.data.domain.PageRequest
(may named "MongoPageRequest") with the extra option for the fields, so queries like that are possible:No further details from DATAMONGO-184