CouchDB Basics

Why CouchDB?


Here is a visual guide to NoSQL systems:

alt text

You can see that CouchDB has picked availability and partition tolerance. This diagram also gives you a good big picture view of how different NoSQL databases fit in the CAP triangle.

Installation


Here is the installation instructions for Mac using the Apache CouchDB native application.

1) Download from Apache website:
http://www.apache.org/dyn/closer.cgi?path=/couchdb/binary/mac/1.6.1/Apache-CouchDB-1.6.1.zip
2) Unzip the Apache-CouchDB-1.6.1.zip file.
3) Move the unzipped 'Apache CouchDB' to Applications folder.

Run CouchDB


Click on the 'Apache CouchDB' application in the Applications folder. It will open the CouchDB admin interface in the browser http://localhost:5984/_utils/. We will play with Futon admin web interface later. For now, let's interact with CouchDB from a terminal using Curl command.

Welcome CouchDB

$curl http://127.0.0.1:5984
{"couchdb":"Welcome","uuid":"d53285f595c9133f3ba9e5599b951410","version":"1.6.1","vendor":{"version":"1.6.1-1","name":"Homebrew"}}

List All Databases

$curl -X GET http://127.0.0.1:5984/_all_dbs
["_replicator","_users","test_suite_db","test_suite_db2"]

Create a Database

$curl -X PUT http://127.0.0.1:5984/espresso
{"ok":true}
$curl -X GET http://127.0.0.1:5984/_all_dbs
["_replicator","_users","espresso","test_suite_db","test_suite_db2"]

If you create a database that already exists:

$curl -X PUT http://127.0.0.1:5984/espresso
{"error":"file_exists","reason":"The database could not be created, the file already exists."}

Delete a Database

Let's create a new database called wave, view all the databases and delete the new database wave.

$curl -X PUT http://127.0.0.1:5984/wave
{"ok":true}
$curl -X GET http://127.0.0.1:5984/_all_dbs
["_replicator","_users","espresso","test_suite_db","test_suite_db2","wave"]
$curl -X DELETE http://127.0.0.1:5984/wave
{"ok":true}
$curl -X GET http://127.0.0.1:5984/_all_dbs
["_replicator","_users","espresso","test_suite_db","test_suite_db2"]

Futon Interface


Go to http://localhost:5984/_utils/ URL in a browser. Click 'Verify Installation' link. Follow the quick tour. The only difference is that this version of CouchDB will show you _rev only after you save the document.

The web interface has changed for this version of CouchDB, so you will not be able to follow the instructions for 'Running a Query using MapReduce'. However you will be able to follow the instructions for 'Triggering Replication'.

The beam.smp process was using 80% of CPU and my MacBook Pro fan was spinning loudly with lot of heat from the laptop. Just go to activity monitor and kill the beam.smp process your laptop will get back to normal within a few minutes. I had to kill two beam.smp processes that had taken over most of the CPU time. After killing both processes, since CouchDB was still running it created a new beam.smp process that did not create any problems. I was able to interact with CouchDB.

Summary


I found CouchDB easy to install and play with it from a terminal. It uses a standard HTTP verbs to interact with the CouchDB server. It would be a great fit for developing your own ESCAPE server for serving configuration information. CouchDB picks availability and partition tolerance. Since consistency is not issue for this type of applications, it's a great fit.

References


1) Installation on Mac OS X
2) CouchDB Definitive Guide
3) Continuous Delivery: Reliable Software Releases through Build, Test, and Deployment Automation by Jez Humble and David Farley
4) Diagram from Stack Exchange
5) Runaway applications can shorten battery runtime, affect performance, and increase heat and fan activity


Related Articles


Ace the Technical Interview

  • Easily find the gaps in your knowledge
  • Get customized lessons based on where you are
  • Take consistent action everyday
  • Builtin accountability to keep you on track
  • You will solve bigger problems over time
  • Get the job of your dreams

Take the 30 Day Coding Skills Challenge

Gain confidence to attend the interview

No spam ever. Unsubscribe anytime.