1

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

Matthew Groves
  • 25,181
  • 9
  • 71
  • 121
Mr.Code
  • 19
  • 1
  • 5

2 Answers2

0

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.

Mr.Code
  • 19
  • 1
  • 5
0

Use Array indexing described at https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/indexing-arrays.html

CREATE INDEX ix1 ON default(DISTINCT cars); 
SELECT d.* FROM default AS d WHERE ANY v IN d.cars SATISFIES v = $1 END;
vsr
  • 7,149
  • 1
  • 11
  • 10