Search code examples
javaspring-bootcouchbasesql++

How to find all the documents in a table which have a given string input as one of the string in list of string column couchbase repository


I wanted to know is there any way to find all the documents in a table which have a given string input as one of the string in list of string column couchbase repository

@Data
@Document
@AllArgsConstructor
@NoArgsConstructor
public class User {
    @Id @GeneratedValue(strategy = GenerationStrategy.UNIQUE)
    private String id;

    @NotBlank
    @Field
    private String username;

    @NotBlank
    @Field
    private List<String> cars;
}

I want to find all the users who have Tesla as one of the value in list of cars I am using ReactiveCouchbaseRepository Thank You


Solution

  • I found a solution to the above question.

    @Query("#{#n1ql.selectEntity} WHERE ARRAY_CONTAINS(cars,$1) AND #{#n1ql.filter}")
    Flux<Course> findAllByCars(String car);
    

    The above query worked for me.