1

I need to get a set of data from 2 collections.

Employee
{"id":"1234",
"name":"Smith"}

Salary{
"employeeId":"1234",
"Salary":"10000"}

I am creating an utility method where I have to fetch the data by joining these two tables and pass the employeeId as param to the N1ql query.

So I am trying to use CouchbaseTemplate.findByQuery from Spring data couchbase 4.3.2.

There is no much documentation available on internet how to achieve this without creating a repository. What can I try?

Matthew Groves
  • 25,181
  • 9
  • 71
  • 121
Ajeesh
  • 11
  • 1

2 Answers2

0

create a query for the matching(query) method :

Query specialUsers = new Query(QueryCriteria.where("firstname").equals("Taylor"));
final List<User> foundUsers = couchbaseTemplate.findByQuery(User.class).withConsistency(REQUEST_PLUS)
        .inCollection(collectionName).matching(specialUsers).all();
Michael Reiche
  • 375
  • 1
  • 7
0

To reference two collections in a single query, an @Query must be used.

template and generated repository queries can only reference one collection.

Michael Reiche
  • 375
  • 1
  • 7
  • Could you merge this with your last answer? I am not sure there is a need for more than one post from one person (unless you are presenting two different ways of solving the problem). – halfer Dec 24 '22 at 12:54
  • 1
    They are two different solutions. One is the preferred way (matching)- but it won't work for the OP's case as they are doing a join across collections. – Michael Reiche Jan 03 '23 at 22:51