Getting started with Apache CouchDB + Fauxton!

Jaque.
The Ksquare Group
Published in
5 min readJul 9, 2019

--

This article is a guide to help you get started with Apache CouchDB features and the native web-based interface.

What is Apache CouchDB?

Apache CouchDB is an open source database that uses JSON to store data (documents). It is focused on ease of use, embracing the web using JavaScript as its language. This effortlessness allows the user to transform documents and regular HTTP protocol for its API to access all types of documents.

What we like about Apache CouchDB is that it uses a document store with data presented in the JSON format. This gives a RESTful HTTP API for reading, editing, adding and deleting documents in the database, from fields that can be numbers, lists, text, etc., to any kind of attachments.

Another interesting fact about Apache CouchDB, not only is it capable of running in operative systems (OS), such as Windows, Linux, and Mac, but also interacts with programming languages such as Python, Django, and Ruby. All with the aim to build traditional server-side applications.

This breed of database management system — first released in 2005 and then as part of the Apache Software Foundation in 2008- is a perfect fit for common applications as it embraces the idea of evolving self-contained documents as the core of its data model.

Apache CouchDB is an amazing database manager that has been growing in performance and popularity in the last years.

Popularity of CouchDB.

Installation guide on Ubuntu 18.04 Bionic

In this section, we will show you how to install CouchDB on Ubuntu 18.04, but before the installation, make sure you are logged in as a user with sudo privileges or set this on the commands and you should install a series of dependency packages by running:

$ sudo apt-get install automake autoconf lib tooll help2man$ sudo apt-get --no-install-recommends -y install build-essential pkg-config erlang libicu-dev libmozjs185-dev libcurl4-openssl-dev

Note: Be sure to check for the current version offered by your distribution.

Once you have done this, we can start the installation guide.

Enabling CouchDB repository

First, we have to add the CouchDB GPG key to our system by installing the repository key:

$ curl -L https://couchdb.apache.org/repo/bintray-pubkey.asc \
| sudo apt-key add -

Then, update the repository cache and install the package:

$ sudo apt-get update && sudo apt-get install couchdb

Finally, check that the server has started successfully:

$ curl http://127.0.0.1:5984

If CouchDB is running, you should see a message like the one shown below:

{“couchdb”:”Welcome”,”version”:”2.3.1",”git_sha”:”c298091a4",”uuid”:”fb2d4e5d1719d8892e042720c8c3b8d1",”features”:[“pluggable storage-engines”,”scheduler”],”vendor”:{“name”:”The Apache Software Foundation”}}

You can now open the Fauxton web administration interface and run _utils with the following URL: http://127.0.0.1:5984/_utils

If you see something like this, ¡Congratulations, CouchDB has already successfully installed!

Web administration interface

Playing with Fauxton!

Fauxton, the native web-based interface built into CouchDB that provides a basic interface to most of the functionality, also provides us with broad access to all CouchDB tools such as creating and deleting databases, performing basic CRUD operations (Create, Read, Edit and Delete) on documents, among other things. On the left navigation panel we can see the features:

  • Databases: This is the default tab, it will show you a create document button, a list of all your databases, their size, number of documents, and action buttons such as: replication, permissions configuration, and replicator removal.
  • Setup: A wizard to set up and configure CouchDB clusters, you can configure a single node or a multi-node.
  • Active Tasks: Shows the tasks that are running in the background in the server including the compaction, replication and the view compaction.
  • Config: In this interface, we can configure all the parameters that are in the list shown.
  • Replication: The interface for the replication system, enabling you to initiate replication between local and remote databases.
  • Documentation: Here we can find the official documentation of CouchDB.
  • Login/User Management: Allows you to change your password, manage or add an administrator to your CouchDB instance.
  • Verify: Verifies your CouchDB installation.

Creating a database!

Creating a database in Fauxton is very simple and friendly. CouchDB handles databases in a slightly different way since being a document-based model, each document stores specific data. An example, where our database called catalog will create a single document for each product.

1. Click “Create Database”, enter a valid name (you can’t use upper case letters). In our case, we chose catalog and then click the create button.

2. Once your database has been created Fauxton will display this:

3. After you create the database, you will see a Create Document button in the upper right corner.

4. We can see a text-based editor. Here, we must capture every value for the document. In our example, the information we want to hold is:

  • title
  • size
  • publish
  • color
  • material

Every new Document has an ID, so we’ll just add a comma to the end and begin the next line with the information we mentioned before. Which will look like this:

{“title”: “Nike Dri-FIT LeBron More Than An Athlete”, “size”: “L”, “published”: “05/10/2019”,  “color”: “Blue”, and  “material”: “poliester”}

Upon completing the document, we will click the “Create Document” button to save it.

Document #1

And now you can create as many documents as you need for the database.

{“title”: “Men’s Training T-Shirt”,  “size”: “M”,  “published”: “05/10/2019”, “color”: “Green”,  “material”: “cotton”}

5. At this point, you can visualize the JSON, but if we pay attention we can see another new field called _rev. This is the revision ID and will have different values every time you change any field of the document.

Conclusions

CouchDB combines an intuitive document storage model with a powerful query engine, and uses JSON, a good format for transporting data that is easy for a human to read, as well as being simple for machines to parse.

The perks of CouchDB can be noted merely from its name: the idea of learning and implementing it on your application will make you want to go to your couch and relax.

--

--