What are the differences in opening bucketA and using it to select bucketB?


#1

I am confused in using couchbase java sdk when I want to use it to execute some N1QLs
For example, there are 2 buckets, BucketA and BucketB.
I want to query the data in BucketA first, so I open the BucketA to query.
But it also works if I want to query the data in BucketB later when I open the BucketA to query.

Should I close the BucketA and then open BucketB to query?
What are the differences in using the same bucket to query and using the different bucket to query another bucket?

    CouchbaseService cs = CouchbaseService.getInstance(IP);
    Bucket bucket_a = cs.OpenBucket("BucketA");
    
    String query1 ="SELECT * FROM BucketA WHERE name = 'jack'";
    String query2 ="SELECT * FROM BucketB WHERE name = 'jack'";
    List<String> qResult=cs.N1qlQuery(query1, bucket_a);
    for (String result : qResult)
    	System.out.println(result);
    //Should I close the BucketA and then open BucketB to query? 
    qResult=cs.N1qlQuery(query2, bucket_a);
    for (String result : qResult)
    	System.out.println(result);

#2

Historically all data operations in Couchbase were tied to a specific bucket, but now N1QL can cross bucket boundaries, allowing to do joins between buckets and the like.

As long as there is no password protection on the buckets you want to query, you can keep using bucket A.

The only challenge here is authentication. We are currently thinking about the design for cross-bucket queries where different buckets need different credentials, and how best to provide these credentials in the SDKs, in a coherent API.