jpaspring-data-jpacouchbasespring-data-couchbasecouchbase-java-api

Spring data query with parameters


I have to create this N1QL couchbase query in Spring data

select... LIKE "TASK:100:%"

where 100 is a parameter, but I don't know if it is possible

@Query("#{#n1ql.selectEntity} where META().id like \"TASK:$1%:\" ")
List<Task> findTasks(String taskId);

Solution

  • The correct syntax would be the following:

    @Query("#{#n1ql.selectEntity} where META().id like ('TASK:' || $1 || '%') ")
    List<Task> findTasks(String taskId);
    

    Although I think you should concatenate the id on the backend instead of inside the query.