Migrate Couchbase parameterized N1ql Query from java SDK 2.x to SDK 3.x


I am migrating Couchbase Java SDK from 2.x to 3.x. can someone please help me how to write logic of executing parameterized N1ql query in java SDK 3. Below is the reactive java code I written in SDK 2.0.

final Flux findResult = repository.getCouchbaseOperations()
.findByN1QL(N1qlQuery.parameterized(findQuery, queryParams), MyObject.class)
.doOnError(ex → LOG.error(“MSG=‘Find query failed’, errorMsg={}”, ex.getMessage()))
.retryWhen(retry.createRetryForN1qlQuery(retryConfig, LOG).build());

Checkout Couchbase Playground

Hi @vsr1 ,

Thanks for your immediate suggestion.

I have few challenge with this approach, I can not use cluster for execute the N1ql query.

Basically my application is connected with two different bucket. For first bucket connection I am managing with couchbase connection String and for 2nd bucket I am using couchbaseClientFactory by injecting java bean of cluster .

And I want to execute N1ql query in the first bucket which is connected with default connection string.


Hi @Vishal_Singh

You can use setPositionalParameters on a Query for this in the SDK 3 version of Spring Couchbase, something like this:

Query query = new Query(QueryCriteria.where(i("firstname")).like("$1"))
List<User> foundUsers = repository.getCouchbaseOperations().findByQuery(User.class).matching(query).all();
1 Like