You can request replication of a database so that the two
databases can be synchronized. By default, the replication
process occurs one time and synchronizes the two databases
together. For example, you can request a single synchronization
between two databases by supplying the source
and target
fields within the request JSON
content.
POST http://couchdb:5984/_replicate Content-Type: application/json Accept: application/json { "source" : "recipes", "target" : "recipes-snapshot", }
In the above example, the databases recipes
and recipes-snapshot
will be synchronized.
These databases are local to the CouchDB instance where the
request was made. The response will be a JSON structure
containing the success (or failure) of the synchronization
process, and statistics about the process:
{ "ok" : true, "history" : [ { "docs_read" : 1000, "session_id" : "52c2370f5027043d286daca4de247db0", "recorded_seq" : 1000, "end_last_seq" : 1000, "doc_write_failures" : 0, "start_time" : "Thu, 28 Oct 2010 10:24:13 GMT", "start_last_seq" : 0, "end_time" : "Thu, 28 Oct 2010 10:24:14 GMT", "missing_checked" : 0, "docs_written" : 1000, "missing_found" : 1000 } ], "session_id" : "52c2370f5027043d286daca4de247db0", "source_last_seq" : 1000 }
The structure defines the replication status, as described in the table below:
Table 9.4. Replication Status
Field | Description |
history [array] | Replication History |
doc_write_failures | Number of document write failures |
docs_read | Number of documents read |
docs_written | Number of documents written to target |
end_last_seq | Last sequence number in changes stream |
end_time | Date/Time replication operation completed |
missing_checked | Number of missing documents checked |
missing_found | Number of missing documents found |
recorded_seq | Last recorded sequence number |
session_id | Session ID for this replication operation |
start_last_seq | First sequence number in changes stream |
start_time | Date/Time replication operation started |
ok | Replication status |
session_id | Unique session ID |
source_last_seq | Last sequence number read from source database |