CouchDB Replication

Leave your reply

Introduction

Learn about using replication with CouchDB. One of CouchDB's core strengths is its replication functions, which allow you to easily synchronize two copies of the same database. The copies can exist on the same server, or on separate servers.

Requirements

  • A Servidor Cloud (Ubuntu 16.04) with CouchDB and Futon installed.

Related articles:

Triggering a One-Time Replication

By default, replication is a one-time action. To trigger a replication, send an HTTP request to the CouchDB installation with information about the source and target databases. CouchDB will send all the information from the source to the target.

Replication can take place between two databases on the same server, or between a local database and one on a remote server. To trigger a replication, visit the Futon admin panel and click Replicator on the menu on the right.

You can choose to replicate databases in either direction. Fill out information on the databases you want to copy changes to and from.

For example, to copy the local database reviews to the same database on an external server at IP address 192.168.0.1 you would fill it out as follows, then click Replicate.

CouchDB replication

The command to use Curl to trigger a replication from the command line is:

For example, to copy the local database reviews to the same database on an external server at IP address 192.168.0.1, the command is:

curl -X POST -d '{"source":"http://127.0.0.1:5984/reviews","target":"http://192.168.0.1:5984/reviews"}' http://127.0.0.1:5984/_replicate -H 'Content-Type: application/json'

Continuous Replication

If you set continuous replication, CouchDB will listen on its API for any changes to the database, and automatically replicate any changed documents.

To configure continuous replication in Futon, select Continuous before you click Replicate.

CouchDB replication

To configure continuous replication from the command line, add "continuous":true to the target. To add continuous replication to the example shown above, the command is:

curl -X POST -d '{"source":"http://127.0.0.1:5984/reviews","target":"http://192.168.0.1:5984/reviews", "continuous":true}' http://127.0.0.1:5984/_replicate -H 'Content-Type: application/json'