I want to write a query to find a list of strings which contains sub-strings, e.g
"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);
what if i want only list not the whole json object
@Query(“Select namelist from test where #{n1ql filter} And ANY v In namelist SATISFIES v Like ‘%’ || $1 ‘%’ END within #{n1ql ucket}”)
then it throws error
org.springframework.data.couchbase.core.CouchbaseQueryExecutionException: Unable to retrieve enough metadata for N1QL to entity mapping, have you selected _ID and _CAS?
@Query(“Select meta().usedcarimages , meta().id as _ID, meta().cas as _CAS From #{n1ql ucket} where #{n1ql .filter} AND ANY imagename IN usedcarimages SATISFIES imagename Like ‘%’ || $1 || ‘%’ END”)
List< String> findByUsedcarimagesContains(String fileName);
then i cant map directly to List< String> it gives error as above mapping error. so i added class name but only got id value and all other null values.
@Query(“Select ARRAY_SORT(META().usedcarimages)[-1],META().id AS _ID, META().cas AS _CAS from #{n1ql bucket} where #{n1ql .filter} AND ANY imagename IN usedcarimages SATISFIES imagename Like ‘%’ || $1 || ‘%’ END”)
String findByUsedcarimagesContains(String fileName);
and got following error,
“Query returning a simple type are expected to return a unique value, got 2”
that means i am getting data but not getting last value .
did remove Meta(). but now value increased from 2 to 3,
Query returning a simple type are expected to return a unique value, got 3
after that i removed Array_sort and [-1] then it worked but got all the values not the last one.
also i cant cast value is List< String >