Couchbase driver

# Introduction

This section explains the Mongock Driver for Couchbase and how to use it.


# Couchbase driver options and compatibility

Mongock provides the CouchbaseDriver, which is compatible with official couchbase Java SDK com.couchbase.client:java-client 3.x.x. CouchbaseDriver is tested against Couchbase Server version 6 and Couchbase Server version 7+, but should be working even with older versions.

You can also use the Mongock spring extension to get advantage from the autoconfigure approach with Springboot.



# CouchbaseDriver common configuration

When setting configuration via properties file, it must be prefixed by mongock.couchbase

# Properties

Property Description Type Default value
scope The custom scope to be used to store the lock and changeset information in couchbase. This value should only be set if you are using Couchbase server 7+ String _default
collection The custom collection to be used to store the lock and changeset information in couchbase. This value should only be set if you are using Couchbase server 7+ String _default


# Get started

Following the get started section, this covers steps 3 and 5 and 6.

# Add maven dependency for the driver (step 2)

# Standalone

<!--Standalone use-->
<dependency>
<groupId>io.mongock</groupId>
<artifactId>couchbase-driver</artifactId>
</dependency>

# With Springboot

<dependency>
<groupId>io.mongock</groupId>
<artifactId>couchbase-springboot-driver</artifactId>
</dependency>

# With Springboot 3

<dependency>
<groupId>io.mongock</groupId>
<artifactId>couchbase-springboot-v3-driver</artifactId>
</dependency>

# Build the driver (setps 5)

This step is only required for builder approach. Mongock handles it when autoconfiguration is enabled.

These classes provide the same two static initializers
CouchbaseDriver driver = CouchbaseDriver.withDefaultLock(cluster, collection);

# Examples

Please visit our example projects in this repo for more information

# Example autoconfiguration with Springboot

spring:
data:
couchbase:
bucket-name: bucket
couchbase:
connection-string: couchbase://localhost:11210
username: Administrator
password: password
mongock:
enabled: true
migration-scan-package: io.mongock.examples.couchbase.springboot.migration
@EnableMongock
@SpringBootApplication
public class QuickStartApp {
public static void main(String[] args) {
SpringApplicationBuilder().sources(QuickStartApp.class)().run(args);
}
}

# Example: Couchbase standalone

Cluster cluster = Cluster.connect(
"couchbase://127.0.0.1",
"Administrator",
"password"
);
Collection collection = cluster.bucket("bucketName").defaultCollection();
CouchbaseDriver driver = CouchbaseDriver.withDefaultLock(cluster, collection);

# Example: Couchbase Springboot Java Config

@EnableMongock
@SpringBootApplication
public class QuickStartApp {
public static void main(String[] args) {
SpringApplication.run(QuickStartApp.class, args);
}
@Configuration
public static class Config extends AbstractCouchbaseConfiguration {
@Override
public String getConnectionString() {
return "couchbase://127.0.0.1";
}
@Override
public String getUserName() {
return "Administrator";
}
@Override
public String getPassword() {
return "password";
}
@Override
public String getBucketName() {
return "travel-sample";
}
}
}