## 7.5. Couchbase

This section describes procedures that can be used to interact with Couchbase.

`CALL apoc.couchbase.get(hostOrKey, bucket, documentId) yield id, expiry, cas, mutationToken, content` | Retrieves a couchbase json document by its unique ID
`CALL apoc.couchbase.exists(hostOrKey, bucket, documentId) yield value` | Check whether a couchbase json document with the given ID does exist
`CALL apoc.couchbase.insert(hostOrKey, bucket, documentId, jsonDocument) yield id, expiry, cas, mutationToken, content` | Insert a couchbase json document with its unique ID
`CALL apoc.couchbase.upsert(hostOrKey, bucket, documentId, jsonDocument) yield id, expiry, cas, mutationToken, content` | Insert or overwrite a couchbase json document with its unique ID
`CALL apoc.couchbase.append(hostOrKey, bucket, documentId, jsonDocument) yield id, expiry, cas, mutationToken, content` | Append a couchbase json document to an existing one
`CALL apoc.couchbase.prepend(hostOrKey, bucket, documentId, jsonDocument) yield id, expiry, cas, mutationToken, content` | Prepend a couchbase json document to an existing one
`CALL apoc.couchbase.remove(hostOrKey, bucket, documentId) yield id, expiry, cas, mutationToken, content` | Remove the couchbase json document identified by its unique ID
`CALL apoc.couchbase.replace(hostOrKey, bucket, documentId, jsonDocument) yield id, expiry, cas, mutationToken, content` | Replace the content of the couchbase json document identified by its unique ID.
`CALL apoc.couchbase.query(hostOrKey, bucket, statement) yield queryResult` | Executes a plain un-parameterized N1QL statement.
`CALL apoc.couchbase.posParamsQuery(hostOrKey, bucket, statement, params) yield queryResult` | Executes a N1QL statement with positional parameters.
`CALL apoc.couchbase.namedParamsQuery(hostOrKey, bucket, statement, paramNames, paramValues) yield queryResult` | Executes a N1QL statement with named parameters.

Copy these jars into the plugins directory:

(Tested with CB Enterprise 5.5.3, note that CB 6 is not yet supported)

    mvn dependency:copy-dependencies
    cp target/dependency/java-client-2.5.9.jar target/dependency/core-io-1.5.2.jar target/dependency/rxjava-1.3.8.jar $NEO4J_HOME/plugins/

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.socketConnectTimeout=<default=1500>
    apoc.couchbase.kvTimeout=<default=2500>
    apoc.couchbase.ioPoolSize=<default=3>
    apoc.couchbase.computationPoolSize=<default=3>

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