Trying out CouchDB for the first time

CouchDB is a document-oriented database written in the Erlang programming language. It is a NoSQL product designed for local replication and to scale vertically along a wide range of devices.

There are several good libraries that will abstract accessing CouchDB from various programing languages. However, in order to understand what goes on in the libraries, I think it is important to first understand what is going on on a lower lever, so that is what I will show you.

Step 1, install CouchDB. CouchDB for OSX can be downloaded here, the bundle contains bouth the Erlang runtime and CouchDB – no compiling or installing needed, just download the .dmg, mount it and run the application! If you are on Linux it is quite likely that CouchDB is in the repository of your distribution. In Ubuntu CouchDB is found in “Universe” and can easily be installed using apt. I haven’t tried CouchDB on Windows so I can’t give you any guidance here, if you try it out, please leave a comment.

Now when CouchDB is installed lets explore it using use one of my favorite tools, good old cURL. Port 5984 is the default port for CouchDB.

$ curl -X GET http://localhost:5984/

CouchDB is up running! Lets create a new database:

$ curl -X PUT http://localhost:5984/testdb

CouchDB’s responses are also in JSON form. Lets inspect the database we just created:

$ curl -X GET http://localhost:5984/testdb

CouchDB returns some statistics of the database, we can see that it contains 0 documents. Lets store an empty document in the database:

$ curl -X POST http://localhost:5984/testdb/ -H "Content-Type: application/json" -d {}

CouchDB returns the unique id for the document and the version number (did i mention that all documents are version controlled?:)). Next step is to fetch all documents:

$ curl -X GET http://localhost:5984/testdb/_all_docs

Yes! it is there! Now you should also be able to see your database “testdb” and the document you created in the CouchDB GUI.


Leave a Reply

Your email address will not be published. Required fields are marked *