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:
Navigate to http://localhost:5984/_utils/ using your web browser.
Create the
catalog-a
andcatalog-b
databases.Create a new, empty document (with only an
_id
field) in thecatalog-a
database.Under “Tools,” click “Replicator.”
Under “Replicate changes from,” leave “Local database” selected, and select “catalog-a.”
Under “to,” leave “Local database” selected, and select “catalog-b.”
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.
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.