Skip to content
This repository has been archived by the owner on Jul 31, 2018. It is now read-only.

Couchdb help

frankrousseau edited this page Feb 5, 2013 · 10 revisions

Setup

For specific installation see this link. For Debian/Ubuntu run this commands :

sudo apt-get install build-essential erlang libicu-dev libmozjs-dev libcurl4-openssl-dev

wget http://apache.mirrors.multidist.eu/couchdb/releases/1.2.1/apache-couchdb-1.2.1.tar.gz
tar -xzvf apache-couchdb-1.2.1.tar.gz
cd apache-couchdb-1.2.1
./configure
make
make install
rm -rf apache-couchdb-1.2.1
rm -rf apache-couchdb-1.2.1.tar.gz

sudo adduser --system --home /usr/local/var/lib/couchdb --no-create-home --shell /bin/bash --group --gecos "CouchDB_Administrator" couchdb
sudo chown -R couchdb:couchdb /usr/local/etc/couchdb
sudo chown -R couchdb:couchdb /usr/local/var/lib/couchdb
sudo chown -R couchdb:couchdb /usr/local/var/log/couchdb
sudo chown -R couchdb:couchdb /usr/local/var/run/couchdb
sudo chmod 0770 /usr/local/etc/couchdb
sudo chmod 0770 /usr/local/var/lib/couchdb
sudo chmod 0770 /usr/local/var/log/couchdb
sudo chmod 0770 /usr/local/var/run/couchdb

Then use a daemon manager like upstart or Python Supervisor. Here is an configuration file couchdb.conf for Python Supervisor :

[program:couchdb]
autorestart=true
autostart=true
command=couchdb
environment=HOME=/usr/local/var/lib/couchdb
redirect_stderr=true

Start Couchdb with Python Supervisor :

supervisorctl start couchdb

Common requests (written with coffeescript)

Get all doc of the same type

map = ->
    emit doc._id, doc if doc.docType is "Note"

Order docs with a given field and filter on this field

map = ->
    emit doc.date, doc

Query, get a doc for a given date :

query = 
    key: mytimestamp

Query, get a doc from a given date to another date :

query = 
    startkey: starttimestamp
    endkey: endtimestamp

Order docs by title and group them by category

map = ->
    emit [doc.category, doc.title], doc

Query, get all docs for a given category:

query = 
    startkey: [category]
    endkey: [category + "0"]

Display data

Connect to http://localhost:5984/_utils . You will access to the Futon UI that allows you to see every data and views set in your CouchDB instance.

Links

CouchDB official website

CouchDB guide