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?"
This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

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 Jul. 3rd, 2025 06:21 pm
Powered by Dreamwidth Studios