CouchDb: document oriented persistence

If you’re looking for something “interesting” to mess around with, Damien Katz’s CouchDb project is at the point of working prototype, the server implemented in Erlang (a hot topic in some places) and a demo client application (a simple forum) in PHP.

Firing up the CouchDb server on Windows is a breeze – follow the README. PHP-wise, you need the new http extension which is most easily done on Win32 by grabbing the most recent PHP 5 release (5.1.6) and the corresponding collection of PECL modules. Alternatively the most recent XAMPP (apparently) packs the extension.

The interface between CouchDb and PHP is REST – XML + HTTP – you can also point your browser directly at the CouchDb server (default – localhost:8080) and get around with a little help from the CouchDb wiki.

What is CouchDb and why is CouchDb interesting, given relational DBs etc? To an extent it’s hard to define – best starting point is probably Damien’s discussion of Document Oriented Development. There’s a quick overview here but still it’s difficult to find a truly selling argument. How about some code instead? Here’s a snippet from the demo app (couchthread2.php), which is handling a form post;

      if ($_SERVER['REQUEST_METHOD'] == 'POST') {             // someone is creating a new response                      // Set a field named Type to "response". This is a simple         // way to identify the "Type" of the document. (but we could         // have as easily used Form, Class, Category etc as a field         // name)         $_POST['Type'] = "response";                  // Add a creation date, and use a format that will sort correctly as text         $_POST['CreationDate'] = date(DATE_ATOM);                  // add the threadid from query arg         $_POST['threadid'] = $_GET['threadid'];              // just take all the posted fields and save them as a new document         if (couch_create_doc('http://localhost:8888/couchtest/', $_POST)) {                 header('Location: ' . $_SERVER['REQUEST_URI']); // reload the page             exit;         }     } 

Let’s just zoom in there on that last part…

          if (couch_create_doc('http://localhost:8888/couchtest/', $_POST)) {                 header('Location: ' . $_SERVER['REQUEST_URI']); // reload the page             exit;         } 

…just pass the $_POST (at least for this simple example). Getting interested yet? And how about that reverse proxy between PHP and the db(s) that’s making load balancing transparent?

From what I’ve seen in Dokuwiki, where wiki pages are stored directly, as-is, on the filesystem, there’s a lot to be said for keeping the “raw resources” in a form that makes them easy to identify. Working out the last modification time (caching), replication / mirroring, administration and a whole host of other stuff gets much easier to manage, vs. a relational database where what constitutes a complete “document” may be spread across multiple tables. Of course the downside is stuff like searching, sorting and relations gets harder – enter CouchDb where (if I’ve understood right) you can “compile” tables from the contents of your raw documents using it’s fabric formula language. Assuming the processing done to create the tables is reproducible, replicating databases across systems would then “only” be a matter of copying the raw documents.

The other side of this is what Erlang enables – designed for telephone switches and functional programming language means no squirrels. A worthwhile read to help things click is Functional Programming For The Rest of Us

A functional program is ready for concurrency without any further modifications. You never have to worry about deadlocks and race conditions because you don’t need to use locks! No piece of data in a functional program is modified twice by the same thread, let alone by two different threads. That means you can easily add threads without ever giving conventional problems that plague concurrency applications a second thought!

…and stuff like transactions (apparently) gets easier with functional programming – no awkward state hanging around after you rollback.

Anyway – one to watch I think.


Category: programming Time: 2006-09-07 Views: 0

Related post

  • How do document-oriented databases implement references? 2011-10-09

    In relational world we have Foreign Keys to reference other entities. But how do document-oriented databases like MongoDb, CouchDb, RavenDb implement references among entities? Update. StackExchange related example. We have Question entity and its ta

  • NoSQL Document-oriented in-memory database written in Java 2015-04-12

    The goals are: Open source Written in Java Available as a Jar file Should not need the installation or configuration of a server or a client Be document-oriented as MongoDB, CouchDB, etc. Work as in-memory database Available in Maven Hazelcast works

  • Document-oriented databases vs plain text files 2016-02-16

    I'm working in a Python program which has to access data that is currently stored in plain text files. Each file represents a cluster of data points that will be accessed together. I don't need to support different queries, the only thing I need is t

  • Provide a URL to a CouchDB document attachment without giving the username/password? 2012-05-22

    I posted this question on DBA, but it got closed and was never reopened even after I rewrote the whole thing to be more specific. I think its more appropriate for programmers anyway :) Background Information I have a CouchDB server (Server B) that is

  • Would this data requirement suit a Document -Oriented database? 2012-08-20

    I have a requirement to allow users to fill in journal/diary entries per day. I want to provide a handful of known journal templates with x columns to fill in. An example might be a thought diary; a user has to record a thought in one column, describ

  • Document-oriented vs Column-oriented database fit 2012-10-01

    I have a data-intensive application that desperately needs a database make-over. The general data model: There are records with RIDs, grouped together by group IDs (GID). The records have arbitrary data fields, (maybe 5-15) with a few of them mandato

  • Can XML columns in Oracle/MS SQL Server replace document oriented databases to some extent? 2013-10-30

    Just a strategic question: I am currently working with frequently changing data schemas and it takes a lot to keep track of versions and specific content. I do, however, have a classic OLTP application, which requires ACID, transactions, joins, singl

  • Catching incoming couchdb documents 2016-01-23

    I would like to be aware of every time a document is sent to couch so that I can process that document via an external service. I know that views are updated automatically, is there some way to hook into that process? Could I define logic in the view

  • Menu options in a document-oriented Windows desktop app 2016-02-05

    I am preparing a prototype for some Windows desktop app that allows users to open a project (document) and work with it. The users have mostly Windows 7, with a chance to get Windows 10 sooner or later. There are only a few actions the users can do,

  • Functional Programming in Commercial Software 2011-05-13

    I was recently discussing functional programming with a co-worker. While the two of us both agreed that FP has some obvious benefits (simpler code, easier to reason about mathematically, etc.), we both wondered whether or not it is or will ever be us

  • Importing json into couchdb such that each object becomes a document 2016-02-15

    I have a JSON file in the following format: "rows": [ { "key": [ null, null, "dco_test_group", "3d3ce6270fdfuashge12e1d41af93179", "test_djougou" ], "value": { "lat": "31.538208354

  • File store: CouchDB vs SQL Server + file system 2010-11-23

    I'm exploring different ways of storing user-uploaded files (all are MS Office documents or alikes) on our high load web site. It's currently designed to store documents as files and have a SQL database store all metadata for those files. I'm concern

  • How to remove all Couchdb versions in Ubuntu 10.04 (server)? ( after multiple installs ) 2011-01-12

    I have done multiple installs of CouchDB using sudo aptitude install couchdb sudo ap-get install couchdb and more recently based on the instructions found at L May I know how do I uninstall or remov

  • Relationships Of Complex Documents In Document Databases 2011-03-22

    I have been looking at a number of document databases (RavenDB, CouchDB, MongoDB) and there are two things about them that I really like and makes me what to incorporate them as much as possible and that is the schema-less natural (not that they are

  • Can't remove CouchDB 2011-11-26

    Under 11.04, when I do sudo couchdb -V, I get a response like "couchdb - Apache CouchDB 1.1.1". When I do couchdb -V, without sudo, I get that no package/program like that is installed. I've tried doing sudo apt-get remove couchdb and purge too,

  • Storing documents in Database vs CMS in JSF, Seam, Hibernate application on cloud 2011-12-20

    I am about to start with an application using JSF 2, Seam 3, Hibernate and Hibernate search with the following characteristics: Users will be uploading documents (pdf, doc). There can be millions of documents. The application will be deployed in the

  • What does it mean for an architectural style to be document-centric? 2013-05-28

    I heard it said that REST is "document-centric". Unclear what this meant, I began poking around and found the term document-oriented being used of databases, particularly NoSQL databases, and in contrast to a barebones key-value store. Thus it s

  • Is there a database system specialized in versioning documents/records? 2014-08-19

    I'm trying to find the "best" database for my application, which involves: Large (or is it?) amount of data (~15GB of text data) Documents organized in hierarchies (up to ~5 levels of nesting) Versioned documents (each has a date) To get things

  • PC program to take photos of documents, correct perspective, rotate and crop them automatically 2014-11-02

    I know of several mobile apps designed to tidy up photos of documents, snapped directly from a phone camera, but I'd like a PC program to do the same thing. I already have a bunch of photos of documents as image files on my PC, which are at higher qu

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 1.262 (s). 13 q(s)