Skip to content

Distinct fields in CouchbaseRepository methods are ignored by Couchbase N1ql statement generator #1200

Closed
@khanium

Description

@khanium

Distinct fields in CouchbaseRepository methods are ignored by Couchbase N1ql statement generator

@Repository
public interface ComponentRepository extends CouchbaseRepository<Component, String> {

  List<Component> findDistinctNameByCreator(String creator); 

}

As a workaround, you can create inline @query and add DISTINCT clause and empty __id and __cas values:

    @Query("SELECT DISTINCT ' ' as `__id`, 0 as `__cas`, name from #{#n1ql.bucket} WHERE #{#n1ql.filter} AND `creator` = $1 ")
    List<Component> findDistinctNameByCreator(String creator);

The expectation is to receive the same output as CouchbaseTemplate does:

return template.findByQuery(Component.class)
                .distinct(DISTINCT_NAME)
                .matching(QueryCriteria.where("creator").eq(creator))
                .all();

Request:
Take into consideration the Distinct fields for generating dynamic n1ql queries from repository methods.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions