
Apache CouchDB is an open-source NoSQL database server designed to store data as JSON documents. CouchDB accepts JavaScript MapReduce syntax and HTTP API as the primary query languages to process data.
Developed in Erlang, CouchDB implements real-time scalability and replication features for highly-available distributed database systems to sync data in low bandwidth network connections. Such features make CouchDB a good choice for developing fault-tolerant banking, telephony, e-commerce, and instant messaging applications.
This guide walks you through installing and implementing the CouchDB database server on Ubuntu 20.04.
To proceed with this guide, you require:
A non-root sudo user.
The Apache CouchDB package is not available in the official Ubuntu repository. Follow the steps below to add a third-party software repository to your system.
SSH to your server as a non-root sudo user.
Update the package information index.
Install curl, apt-transport-https, and gnupg dependency packages.
Download the CouchDB gpg package key. The apt tool requires it to trust a third-party repository.
Add the CouchDB repository to the list of available and downloadable packages.
Update the package information index to refresh the new repository entry.
Install the couchdb package.
Press Tab and then Enter to proceed with the installation.
Select standalone configuration in the next step. Then, press Tab followed by Enter to proceed.
Leave the value of the bind-address as 127.0.0.1 and press Tab and then Enter to continue.
Type in your preferred administrator password and press Tab followed by Enter to proceed.
Repeat the administrator password and press Tab then Enter to continue.
You've now completed the CouchDB installation. Manage the couchdb package using the following commands.
Start the couchdb service.
Stop the couchdb service.
Enable the couchdb service to start at boot.
Restart the couchdb service.
You can execute queries on the CouchDB database server using two methods.
The CouchDB HTTP API. CouchDB ships with a JSON REST API that allows you to interact with the database server by sending requests via the HTTP protocol.
The CouchDB Fauxton interface. This web-based software provides an intuitive interface for managing your CouchDB on a web browser.
You can interact with the CouchDB API using different HTTP clients. This guide uses the Linux curl command to perform basic database operations.
Execute the command below to return basic information about the installed CouchDB server. Replace EXAMPLE_PASSWORD with the correct password for the administrator account.
You should receive the following output.
Create a new demo database.
Output.
List the available databases.
Output.
Create three documents in the demo database. Define each document's data in JSON format and specify a unique ID in the URL using the format ../demo/"1"..., ../demo/"2"..., and ../demo/"3"....
Output.
List all documents from the demo database.
Output.
Get the details of a single document by specifying its unique ID in the URL. For instance, .../demo/1, .../demo/2, or .../demo/3.
Update a document by specifying its unique ID in the URL (/demo/1/) and defining the last _rev (1-b626670af2e7ee1ae13ffba7ffe83819) ID in the JSON body.
CouchDB updates the document and assigns a new revision ID as shown below.
List the document one more time to check the new changes.
The product details are now updated.
CouchDB doesn't support partial updates to existing documents. However, the update command creates a new document version using the supplied data. Therefore, you can't append new fields to an existing document.
Deleting a document. You must specify the document's unique ID and the revision ID in the query URL to delete it from a database.
Retrieve the revision ID using the command below for the product with a unique ID of 3.
Output.
Specify the document ID (3) and the revision ID (1-1ebf435bdc37cf3c5dd32aebdd377d46) in the command below to delete the product.
Output.
Try retrieving the document one more time.
You should now get the error below.
Administering the CouchDB server via the Fauxton interface requires some configuration changes. Follow the steps below to edit the default CouchDB settings.
Open the /opt/couchdb/etc/local.ini file in an editor.
Locate the ;bind_address = 127.0.0.1 entry.
Remove the leading ; character to uncomment the bind_address setting and change its value from 127.0.0.1 to 0.0.0.0. This setting allows CouchDB to listen to all network interfaces.
Restart the CouchDB server to apply the new changes.
Visit the URL below on a web browser and replace 192.0.2.1 with the public IP address of your server.
The Fauxton login screen appears as shown below.
Log in to the web interface by entering the username (admin) and your password (For instance, EXAMPLE_PASSWORD). Click Log In to proceed. The Fauxton software should now navigate you to the following dashboard screen.
Use the Fauxton web interface to perform basic database administration tasks such as creating, retrieving, updating, and deleting databases and documents.
This guide is a walk-through for installing and implementing Apache CouchDB on the Ubuntu 20.04 server. To learn more about CouchDB features, visit the official Apache CouchDB website.
0 Comments
Be the first to comment and share your perspective with the community.