Archive for the ‘ CouchDB ’ Category

CouchDB – New Features in Replication

CouchOne – Blog – What’s new in Apache CouchDB 0.11 — Part Three: New Features in Replication.

Afficher l'image en taille réelle

Without a doubt, replication is CouchDB’s coolest feature. It allows you to synchronise any two databases, local or remote. There is no role-distinction between databases, no master-slave limitations, everybody is a master (if you want master-slave, simply don’t write to one master and thus make it a slave).

This allows you to build a replication infrastructure that fits your application and deployment needs best: two offices with an ocean in between, no problem; large server cluster in one or more data centres, no problem. And anything in between really.

Replication is not new, it has been baked into CouchDB from the beginning. Today, I’ll show you some of the nifty features we added to the 0.11 replicator to make your life a little easier.

To recap, here is how you trigger replication from CouchDB running on your local machine to synchronise a local database with a remote database:

curl -X POST 
-d '{"source":"database", 

Note: The backslash means “keep reading the command on the next line” to make things more readable and so you can copy and paste the commands into your command line.

Update 05.12.2010: From CouchDB 1.0 on you need to send the correct content type, just add -H 'Content-Type: application/json' to the command line.

If you want to read up on CouchDB replication, check out the chapters Replication and Conflict Management from our book, CouchDB: The Definitive Guide.

Implicitly Create Target Database

This is a small yet useful tip. Prior to 0.11, if you wanted to replicate, the target database would have to exist. This can be a mild annoyance at times, so we added a replicator option to implicitly create target databases, if they don’t exist.

Using it is easy, here’s the curl command:

curl -X POST 
-d '{"source":"database",