How to execute dynamic n1ql query with Spring data CouchbaseTemplate

I am migrating spring data couchbase to 4.*

With previous version, I used to execute dynamic N1Ql query like below
N1qlQueryResult result = couchbaseTemplate.queryN1QL(N1qlQuery.simple(complexStringQuery));

Now with upgrade, I see queryN1QL is removed and we are supposed to use findByQuery.
But findByQuery does not take string query.

How can I achieve this with newer spring data couchbase version.

Thank You for your help


If you want to do your own queries then you have to use the Java SDK directly with the Cluster object, like in this example. You can see more detail on this querying in the Java 3.x SDK documentation.

There also some guidance on migrating from Spring Data Couchbase 3.x to 4.x that may assist you.

Hope this helps,

Hi @Deepak_Naik Did you find any solution for your problem, I have same issue that findByQuery is not accepting String query. I can not use couchbase sdk as i have custom deserializer. Any response will be appreciated.

This will use the provided n1qlString fro your query. Don’t forget to project __cas and __id, or you will get an error.

… queryN1ql(String n1qlString)

Alternatively, you can replace only a portion of your query…

@Query ("#{#n1ql.selectEntity} WHERE #{[0]}")
… queryN1ql(String n1qlWhere)