Skip to content

CouchDB - Creating a Database

A database is the top-level container in CouchDB where your JSON documents are stored. You can create databases using the HTTP API (commonly via a tool like cURL) or through Fauxton, the modern web interface for CouchDB.

Creating a Database using the HTTP API (with cURL)

Section titled “Creating a Database using the HTTP API (with cURL)”

You can create a database by sending a PUT HTTP request to your CouchDB instance. The name of the database is specified in the URL path. For security, modern CouchDB setups should have an admin user. The examples below include authentication.

The basic syntax is as follows:

# Syntax: curl -X PUT http://<user>:<password>@<host>:<port>/<database_name>
# The -u flag is a cleaner way to provide credentials.
curl -X PUT http://127.0.0.1:5984/new_database -u admin:password

Here, -X PUT specifies the HTTP method. The -u admin:password flag provides the credentials for an admin user. If your CouchDB instance is not secured (not recommended for production), you can omit the -u flag.

Let’s create a database named user_profiles:

$ curl -X PUT http://127.0.0.1:5984/user_profiles -u admin:secret
{
"ok": true
}

The server responds with a JSON object containing "ok": true, indicating the operation was successful.

To verify that the database was created, you can request a list of all databases from the /_all_dbs endpoint. You should see user_profiles in the list.

$ curl -X GET http://127.0.0.1:5984/_all_dbs -u admin:secret
["_global_changes", "_replicator", "_users", "user_profiles"]

Creating a Database using Fauxton (Web Interface)

Section titled “Creating a Database using Fauxton (Web Interface)”

Fauxton is the official web-based administration UI for CouchDB (version 2.0 and newer), replacing the older Futon. It provides a user-friendly way to manage your databases.

Follow these steps to create a database:

  • Open your web browser and navigate to the Fauxton UI, typically at http://127.0.0.1:5984/_utils/.
  • If prompted, log in with your admin credentials.
  • Click the ‘Databases’ icon (looks like a stack of cylinders) on the left-hand navigation menu.
  • Click the + Create Database button located at the top right of the page.
  • A dialog box will appear. Enter your desired database name, for example, invoices.
  • For the ‘Partitioning’ option, you can select ‘Non-partitioned’ for general use. Partitioned databases are an advanced feature for improving performance in large, clustered deployments.
  • Click the ‘Create’ button. Your new database will now appear in the list.

It is a best practice to use a consistent naming convention for your databases. CouchDB requires names to start with a lowercase letter and can only contain lowercase characters (a-z), digits (0-9), and the special characters _, $, (, ), +, -, and /.