I'll put this disclaimer up right away: My experience with
[[http://couchdb.apache.org/][CouchDB]] and
[[http://benoitc.github.com/couchbeam/][Couchbeam]] is limited so I am
definitely missing out on some knowledge and understanding that would
probably make things easier. I won't detail CouchDB's offerings here as
I have noted above my limited insight into that world. I will try to
comment on using Couchbeam to get documents into and out of CouchDB, as
well as writing a layer to take Couchbeam's document format and cleaning
it up into slightly prettier Erlang data structures (proplists of
binaries just aren't fun to type). The first thing to do is to connect
to your database and get the PIDs for the connection and the DB using
the couchbeam\_server:start\_connection\_link/{0,1} and
couchbeam\_db:open\_or\_create/2. Couchbeam allows you to name the DB
PID so you don't have to carry it around with you; just pass
{DB\_NAME\_AS\_ATOM, "DB\_NAME\_AS\_LIST"} as the second parameter to
open\_or\_create/2. Now calls can use DB\_NAME\_AS\_ATOM instead of the
DB process's PID to communicate. The biggest stumbling block out of the
gate is the datatypes used by Couchbeam. Look at the API docs and get
familiar with the types you'll be expected to provide and receive from
the calls to the database and views. A document is either a
json\_object() or a 2-tuple {DocID, Revision}. A json\_object is a
proplist of [{json\_string(), json\_term()}]. json\_strings are simple,
atom or binary. A json\_term is an atom, binary, integer, float, a list
of json\_terms, or another json\_object(). Practically, for my needs,
all keys are binaries and the majority of values are either binaries or
numeric. I do have one place where I need to store a nested
json\_object(); wrap it in a 1-tuple as the value and you should be
good.

#+BEGIN_EXAMPLE
    %% nesting a json_object() as a value in a json_object()
    ToNest = [{< >, < >}],
    [{< >, < >},
     {< >, { ToNest } }].
#+END_EXAMPLE

Saving a doc is pretty easy; create the proplist and pass it to
couchbeam\_db:save\_doc/2. One big gotcha when saving a document was
whether the < > key existed. If the \_rev key was undefined, a big ugly
bad\_match error was thrown with all sorts of chaos going on around it.
