I am newbie. I am using Java SDK 2.2.0 on Couchbase 4.0 RC0 to run some N1QL queries which joins more than one bucket. In Java SDK, query is a functionality exposed by the bucket interface. So, if I want to run a N1QL query joining more than one bucket which bucket should I get a handle for (i.e. which bucket name should I pass when invoking Cluster.openBucket(…)). Operations like insert, upsert, delete etc being tied to a bucket makes sense because they working on a document in a bucket but shouldn’t a query be more generic?
Does CouchbaseCluster.create() and Cluster.disconnect() create the necessary connections to the cluster? If so, what does opening and closing a bucket do?
(copied from my answer on StackOverflow)
- It is true that N1QL is a bit less tied to the Bucket than the rest of the operations in the API, but we went with adding the query method there, because we figured most people already using the SDK would be accustomed to deal with the
Bucket and probably a lot of N1QL use cases will only span 1 bucket.
However to answer your question, it doesn’t matter which
Bucket reference you use, both will work.
Cluster.create() will compile the list of seed nodes to bootstrap from and prepare the ConfigurationManager so that the SDK can receive updates from the cluster. The actual connection, authentication dance and establishment of main resources is done when calling