Data Sync Locally on Device
Description — Couchbase Lite Database Sync - Synchronize changes between databases on the same device
Related Content — Remote Sync Gateway | Peer-to-Peer Sync
Overview
Couchbase Lite supports replication between two local databases at the database, scope, or collection level. This allows a Couchbase Lite replicator to store data on secondary storage. It is useful in scenarios when a user’s device is damaged and its data is moved to a different device.
-
Kotlin
-
Java
// This is an Enterprise feature:
// the code below will generate a compilation error
// if it's compiled against CBL Android Community Edition.
// Note: the target database must already contain the
// source collections or the replication will fail.
val repl = Replicator(
ReplicatorConfigurationFactory.newConfig(
target = DatabaseEndpoint(targetDb),
collections = mapOf(srcCollections to null),
type = ReplicatorType.PUSH
)
)
// Start the replicator
// (be sure to hold a reference somewhere that will prevent it from being GCed)
repl.start()
thisReplicator = repl
// This is an Enterprise feature:
// the code below will generate a compilation error
// if it's compiled against CBL Android Community Edition.
// Note: the target database must already contain the
// source collections or the replication will fail.
final Replicator repl = new Replicator(
new ReplicatorConfiguration(new DatabaseEndpoint(targetDb))
.addCollections(srcCollections, null)
.setType(ReplicatorType.PUSH));
// Start the replicator
// (be sure to hold a reference somewhere that will prevent it from being GCed)
repl.start();
thisReplicator = repl;