Couchbase

Qualified Name Type Release

apoc.couchbase.get

- retrieves a couchbase json document by its unique ID.

Procedure

APOC Full

apoc.couchbase.exists

- check whether a couchbase json document with the given ID does exist.

Procedure

APOC Full

apoc.couchbase.upsert

- insert or overwrite a couchbase json document with its unique ID.

Procedure

APOC Full

apoc.couchbase.append

- append a couchbase json document to an existing one.

Procedure

APOC Full

apoc.couchbase.prepend

- prepend a couchbase json document to an existing one.

Procedure

APOC Full

apoc.couchbase.remove

- remove the couchbase json document identified by its unique ID.

Procedure

APOC Full

apoc.couchbase.replace

- replace the content of the couchbase json document identified by its unique ID.

Procedure

APOC Full

apoc.couchbase.query

- executes a plain un-parameterized N1QL statement.

Procedure

APOC Full

Install Dependencies

(Tested with CB Enterprise 5.5.3)

The Couchbase procedures have dependencies on a client library that is not included in the APOC Library. This dependency is included in apoc-couchbase-dependencies-4.3.0.12.jar, which can be downloaded from the releases page. Once that file is downloaded, it should be placed in the plugins directory and the Neo4j Server restarted.

Alternatively, you could copy into the plugins directory, from maven repository, the Couchbase Java SDK, and the Couchbase JVM Core IO

Usage

To interact with Couchbase you can define the host on which to connect to as the first parameter of the procedure (with bucket as second parameter, document_id as third parameter):

CALL apoc.couchbase.get('couchbase://Administrator:password@localhost', 'default', 'artist:vincent_van_gogh')

Otherwise you can use configuration properties in the same way as MongoDB. For example, you can add the following properties to the apoc.conf file:

apoc.couchbase.mykey.username=Administrator
apoc.couchbase.mykey.password=password
apoc.couchbase.mykey.uri=host1,host2,host3 // here you can define more than one hostname if you're using a cluster
apoc.couchbase.mykey.port=8091 // the bootstrapHttpDirectPort (optional)
CALL apoc.couchbase.get('mykey', 'default', 'artist:vincent_van_gogh')

You can also define some CouchbaseEnvironment parameters in the apoc.conf:

apoc.couchbase.connectTimeout=<default=5000>
apoc.couchbase.kvTimeout=<default=2500>
apoc.couchbase.ioPoolSize=<default=3>

In order to get an in-depth description of these configuration params please refer to the Official Couchbase Documentation

Configuration parameters

The procedures support the following config parameters:

Table 1. Config parameters
name type default description

collection

String

"_default"

the collection to use. See Scope and collections

scope

String

"_default"

the scope to use. See Scope and collections

compressionEnabled

boolean

true

If enabled, the client will compress documents before they are sent to Couchbase Server. See here.

compressionMinSize

Integer

32

Size in bytes. Documents smaller than this size are never compressed.

compressionMinRatio

Double

0.83

A value between 0 and 1. Specifies how "compressible" a document must be in order for the compressed form to be sent to the server.

mutationTokensEnabled

boolean

true

Mutation tokens allow enhanced durability requirements as well as advanced N1QL querying capabilities. Set this to false if you do not require these features and wish to avoid the associated overhead.

retryStrategy

Enum[FAILFAST, BESTEFFORT]

BESTEFFORT

The client’s default retry strategy. A retry strategy decides whether a failed operation should be retried. See here.

transcoder

Enum[DEFAULT, RAWJSON, RAWSTRING, RAWBINARY]

DEFAULT

The transcoder responsible for converting KV binary packages to and from Java objects.

connectTimeout

Long

null

The connection timeout (in milliseconds) used when a Bucket is opened. If null will be used the apoc.conf parameter apoc.couchbase.connectTimeout.

kvTimeout

Long

null

The Key/Value default timeout (in milliseconds) used on operations which are performed on a specific key. If null will be used the apoc.conf parameter apoc.couchbase.kvTimeout.

disconnectTimeout

Long

10000

The disconnect timeout (in milliseconds) is used when a Cluster is disconnected

queryTimeout

Long

75000

The Query timeout (in milliseconds) used on all N1QL query operations

analyticsTimeout

Long

75000

The Analytics timeout (in milliseconds) used on all Analytics query operations.

viewTimeout

Long

75000

The View timeout (in milliseconds) used on view operations. If there is a node failure during the request the internal cluster timeout is set to 60 seconds.

searchTimeout

Long

75000

The Search timeout is used on all FTS operations

configPollInterval

Long

2500

The interval at which the client fetches cluster topology information in order to proactively detect changes.

idleHttpConnectionTimeout

Long

4500

The length of time an HTTP connection may remain idle before it is closed and removed from the pool. Durations longer than 50 seconds are not recommended, since some services have a 1 minute server side idle timeout.

enableTcpKeepAlives

boolean

true

If enabled, the client periodically sends a TCP keepalive to the server to prevent firewalls and other network equipment from dropping idle TCP connections.

tcpKeepAliveTime

long

60000

The idle time after which a TCP keepalive gets fired. (This setting has no effect if enableTcpKeepAlives is false.) TODO

enableDnsSrv

boolean

true

Gets the bootstrap node list from a DNS SRV record. TODO

networkResolution

com.couchbase.client.core.env.NetworkResolution

null

The network resolution. See here for details.

trustCertificate

boolean

null

If not null, it is the path to a file containing a single X.509 certificate to trust as a Certificate Authority when establishing secure connections. This enable Tls, if present. See here for details.

waitUntilReady

Long

null

This method will wait until either the cluster state is "online" by default, or the timeout is reached.