spring-data-mongodb icon indicating copy to clipboard operation
spring-data-mongodb copied to clipboard

Support distinct queries through query derivation [DATAMONGO-1985]

Open spring-projects-issues opened this issue 7 years ago • 1 comments

Mark Paluch opened DATAMONGO-1985 and commented

It would be great to support distinct queries using closed projections and repository query methods. Given a closed projection selecting a single field (or string queries projecting a single field) we should be able to construct distinct queries.

public interface FooBarRepository extends ReactiveCrudRepository<FooBar, String> {

    Flux<IdentifierOnly> findDistinctByFooAndBar(String foo, String bar);
}

The document / collection class:

@Document
public class FooBar {

    private String identifier; // not unique
    private String foo;
    private String bar;
    // extra fields

    // getters and setters
}

The closed projection:


public interface IdentifierOnly {

    getIdentifier();
}
 

Reference URL: https://stackoverflow.com/questions/50473631/spring-data-mongodb-reactive-distinct-not-working

spring-projects-issues avatar May 22 '18 20:05 spring-projects-issues

I would add that the documentation is very confusing since it seems to imply that the distinct keyword is supported while it is not. (See https://docs.spring.io/spring-data/mongodb/reference/5.0/repositories/query-methods-details.html, among others.)

shollander avatar Nov 26 '25 15:11 shollander