leynos: (Default)
[personal profile] leynos
Today I've been trying to get my head around CouchDB. And yes, when you finally understand it, it is alarmingly simple.

CouchDB is one of those newfangled NoSQL databases. Specifically, it's a document store. This initially left me scratching my head, since it has no tables and no schemas. Records in CouchDB are a collection of arbitrary key value pairs.

The key to understanding how to make use of this all would appear to be views. Views are analogous to indices in an RDBMS. They are composed of two JavaScript functions—map and reduce. This is already getting into scary functional programming territory and you can see me glancing around for the exit at this point.

It's actually not that bad. Map takes a document as its parameter and emits a key value pair. This pair is then inserted as a leaf in a search tree. (Specifically a B-Tree). Every time you create or update a document it is passed to the various view functions to update these views.

The important thing here (the bit that I took my time getting my head around) is that the key in this pair need not be unique within the view. You can also then query these views by key. This gives you your entity relationships.

The reduce part of the view gives you the aggregate functionality of an RDBMS. The number of employees grouped by city, to use the archetypical example. Reduce takes a collection of values and returns a single value. These values are then stored in the branches of the search tree to accelerate future aggregate queries on slices of the keyspace.

There are also validation and transformational functions, but those are a bit more straight forward. What I hope I've noted down here is the answer to the question I was asking myself this morning, "How are you supposed to use a NoSQL database?"
From:
Anonymous( )Anonymous This account has disabled anonymous posting.
OpenID( )OpenID You can comment on this post while signed in with an account from many other sites, once you have confirmed your email address. Sign in using OpenID.
User
Account name:
Password:
If you don't have an account you can create one now.
Subject:
HTML doesn't work in the subject.

Message:

 
Notice: This account is set to log the IP addresses of everyone who comments.
Links will be displayed as unclickable URLs to help prevent spam.

Profile

leynos: (Default)
leynos

January 2015

S M T W T F S
    123
456 78910
11121314151617
18192021222324
25262728293031

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Sep. 21st, 2017 05:38 pm
Powered by Dreamwidth Studios