Chapter 3. Replication

Replication in CouchDB is peer-based and bi-directional, although any given replication process is one-way, from the source to the target. Replication can be run from Futon, CouchDB’s web administration console, or by sending a POST request to _replicate containing a JSON object with replication parameters. Let’s assume we have two databases, both running on the same CouchDB node, that we want to replicate: catalog-a and catalog-b (we can also replicate databases on different CouchDB nodes).

Using Futon:

  1. Navigate to http://localhost:5984/_utils/ using your web browser.

  2. Create the catalog-a and catalog-b databases.

  3. Create a new, empty document (with only an _id field) in the catalog-a database.

  4. Under “Tools,” click “Replicator.”

  5. Under “Replicate changes from,” leave “Local database” selected, and select “catalog-a.”

  6. Under “to,” leave “Local database” selected, and select “catalog-b.”

  7. Click the “Replicate” button. Figure 3-1 shows how everything should look (the details under “Event” will be different for you). Optionally, you could have checked “Continuous” to trigger continuous replication.

Replicating from catalog-a to catalog-b using Futon

Figure 3-1. Replicating from catalog-a to catalog-b using Futon

If you would prefer to use cURL, first create the catalog-a database:

curl -X PUT http://localhost:5984/catalog-a

The response:

{"ok":true}

Create the catalog-b database:

curl -X PUT http://localhost:5984/catalog-b

The response: ...

Get Scaling CouchDB now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.