简体   繁体   中英

How to write Couchbase N1QL query in spring data?

I want to write a query to find a list of strings which contains sub-strings, eg

 "xyz-1",
 "xyz-2",
 "xyz-3",
 "xyz-4".....

Above is list of Strings i need to find but i have input as xyz only and not the fullname xyz-1.

In couchbase server i have implemented the query as below,

SELECT * FROM test
WHERE ANY v IN namelist SATISFIES v LIKE '%xyz%' END;

which will give me all the list name containing xyz. But implementing in Spring boot application its not working.

Below is my spring boot @query menthod

@Query("Select * from `test` where #{#n1ql.filter} And ANY v In namelist SATISFIES v Like '%$1'% END within #{#n1ql.bucket}")
List<String> findBynameList(String name);

and below is my pojo class,

    @Id
    private String car_id;
    @Field
    @NotNull
    private String name;
    @Field
    private List<String> namelist;

Right side of the LIKE must be string or query named/positional parameters of string.

If query named/positional parameters inside the string will not be replaced. You have '%$1'%, it will look for $1 not value.

If you want look for value write like this

v LIKE $1    ===> supply $1 as "%actualvalue%"
v LIKE "%" || $1 || "%" 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM