Do you want to quickly experience CouchDB's powerful replication? Jan Lehnardt, one of the people behind CouchDB, announced yesterday that he'd made a copy of the very good book Pro Git available as a CouchDB Application (a CouchApp). There are two ways you can go about getting that:

  1. Follow his instructions on getting the app with git, for which you'll need an installed couchapp program.
  2. Continue reading. (Hint: this is much more sexy and more in line with showing off what CouchDB is capable of.)

What I'm going to show you here, is how to replicate the content of the progit database Jan created. The result will be a copy of the Pro Git book on your machine:

I'm assuming that you

  • have a running copy of CouchDB on a machine. (On a Mac, I recommend Jan's one-click CouchDB package; download, double-click, relax. :-) )
  • your CouchDB is running on address 127.0.0.1 and port 5984 (the defaults).

Send off a replication command to your CouchDB to "pull" the content of the database.

curl -X POST http://127.0.0.1:5984/_replicate -d \
          '{"source":"http://progit.couchone.com/progit",\
            "target":"progit",\
            "create_target":true}'

This instructs your CouchDB to connect to the source URL and start replicating the progit database. Your CouchDB will create the target database, also called progit. (Note: the create_target option is new for CouchDB 0.11; if you have an older version omit the option and pre-create the database in Futon.) This can take a bit of time. When replication finishes, you should see the results, which will look something like this (reformatted for clarity):

{
       "ok" : true,
       "history" : [
          {
             "docs_read" : 10,
             "session_id" : "9c6ec637a9686e3078de963fa6774c56",
             "recorded_seq" : 10,
             "end_last_seq" : 10,
             "doc_write_failures" : 0,
             "start_time" : "Tue, 04 May 2010 06:54:22 GMT",
             "start_last_seq" : 0,
             "end_time" : "Tue, 04 May 2010 07:04:50 GMT",
             "missing_checked" : 0,
             "docs_written" : 10,
             "missing_found" : 10
          }
       ],
       "session_id" : "9c6ec637a9686e3078de963fa6774c56",
       "source_last_seq" : 10
    }

Now point your Web browser at your own CouchDB instance (which is probably running on 127.0.0.1), with a URL of

http://127.0.0.1:5984/progit/_design/chacon/_show/chapter/01-chapter1

which should get you a page that looks like what you saw above.

After browsing around a bit, I recommend you use Futon to access your CouchDB instance (http://127.0.0.1:5984/_utils/index.html) and look at what is there. Fascinating.

And, if you didn't feel like doing all that and simply want to see what it looked like, you can do so here.

Flattr this
Books, Database, MacOSX, CLI, Replication, CouchDB, and NoSQL :: 04 May 2010 :: e-mail

Comments

blog comments powered by Disqus