1

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

Matthew Groves
  • 25,181
  • 9
  • 71
  • 121
Deepak Naik
  • 43
  • 1
  • 5

2 Answers2

2

Because Couchbase 6.6 and 7 added support for scopes and collections, the query was moved to the cluster/bucket level:

@Autowired
private Cluster cluster;

@Autowired
private Bucket bucket;

...

    cluster.query(N1qlQuery.simple("Select * From myBucket",
            N1qlParams.build().consistency(ScanConsistency.REQUEST_PLUS))).allRows();

    //or
    
    bucket.query(N1qlQuery.simple("select * from Buckey")).allRows();
deniswsrosa
  • 2,421
  • 1
  • 17
  • 25
  • I could not find N1qlQuery.class in the classpath, looks like class is removed in new version. I knew that we can achieve this using CB client like `cluster.query("Select * From myBucket").rowsAs({TragetType}.class);` but I was looking whether anything available from Spring cocuhbase side – Deepak Naik Aug 11 '21 at 20:31
0

I have a solution to "findByN1QL" using cluster,

//      return getCouchbaseOperations(repository).findByN1QL(N1qlQuery.simple(query),
//              DetailDocument.class);
        return cluster.query(query).rowsAs(DetailDocument.class);

Does it work or not? Does anyone have any idea about it?

gimhanas
  • 69
  • 5
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 23 '22 at 12:47