A newer version of this documentation is available.

View Latest

Connecting

Connecting your client SDK to a Couchbase cluster.
Connecting to Couchbase, in pseudo code
client = (new Cluster(‘couchbase://node’)).openBucket(‘travel-sample’)
client = new Bucket(‘couchbase://node/bucket?option1=value1&option2=value2’)
client = new Bucket(‘couchbase://node://bucket’, ‘bucketPassword’)

Connecting to cluster is done by creating a new SDK instance (or handle, or object) and providing the cluster address and bucket name as input parameters.

The cluster address specifies how to contact the Couchbase cluster, and the bucket name specifies which data bucket should be accessed.

Once an SDK instance is connected, it may be used to access data.

Information about the cluster location and bucket to use may be specified by a connection string. A connection string is a URI-like string which specifies the cluster node(s) and the bucket to connect to. It may also specify additional options.

The connection string uses a scheme (couchbase://) followed by the host (which is an IP or hostname of any KV cluster node) and a bucket (as the connection string’s path). Additional connection options can be specified in a URL-style format.

If using multidimensional scaling, it is recommended to specify only data (KV) nodes in the connection string.

See Advanced connection details for a detailed overview of the connection process, and tips to ensure best performance and application behavior.

Connecting from an SDK

Most Couchbase SDKs will accept a connection string, however the other object names, verbs, and options are very SDK specific.

Provided below is an example in Python. Links to examples for other SDKs are found below.

Connecting to a cluster, in Python
from couchbase.bucket import Bucket
cb = Bucket('couchbase://10.0.0.31/default')
cb.upsert('docid', {'new': 'document', 'fields': []})

node.js | Java | Go | .NET | C | Python

Connecting from the command line

You may direct the cbc command line utility to a cluster by specifying the connection string via the -U option, for example:

$ cbc cat airport_4542 -U couchbase://10.0.0.31/travel-sample

Connection string examples

Connect to localhost, default bucket
couchbase://localhost/default
Connect to localhost non-default bucket
couchbase://localhost/travel-sample
Connect remote IP, non-default bucket
couchbase://10.4.3.42/travel-sample
Connect to remote hostname
couchbase://cbnode3.mybiz.com/default
Connect to multiple nodes
couchbase://10.4.3.41,10.4.3.42,10.4.3.43/default
See Advanced connection details for more information on connecting to multiple nodes.
Connect with options
couchbase://cbnode3.mybiz.com/default?operation_timeout=5.5&config_total_timeout=15&http_poolsize=0

Additional options may be found in the connection string reference for your SDK.