CouchDB – Delete Database

You can delete a database in CouchDB by sending an HTTP DELETE request to the database URL or by using the CouchDB web interface, commonly called Fauxton. Both methods permanently remove the selected database and its documents.

Before deleting a database, confirm its name and create a backup when the data may be needed later. Deleting a CouchDB database is destructive and is not the same as deleting a single document.

Delete a CouchDB Database via REST API

Send a HTTP DELETE request with the following URL.

http://hostname/database_name/

We have our CouchDB running in our localhost. Hence, we shall use 127.0.0.1:5984 as hostname.

Let us delete the CouchDB database named cars.

The resulting request URL that we have to use for DELETE request will become,

http://127.0.0.1:5984/cars/

We will use Postman, to trigger a DELETE request with the URL to delete CouchDB Database. You can use any other CLI or GUI tool of your choice.

CouchDB - Delete Database

When the deletion succeeds, CouchDB normally returns a JSON response containing "ok": true.

{"ok":true}

Delete the CouchDB Database with curl

You can send the same DELETE request from a terminal by using curl.

</>
Copy
curl -X DELETE http://127.0.0.1:5984/cars

If your CouchDB server requires authentication, include the administrator username and password. Replace the example credentials with the values configured on your server.

</>
Copy
curl -X DELETE http://127.0.0.1:5984/cars \
  --user admin:password

Verify That the CouchDB Database Was Deleted

Let us check if the database is deleted.

Send a HTTP GET Request with the same URL as above.

CouchDB - Delete Database - Confirmation

The database has been deleted and hence not present.

You can also verify the result from the terminal:

</>
Copy
curl http://127.0.0.1:5984/cars

If the database no longer exists, CouchDB returns a not-found response similar to the following.

{"error":"not_found","reason":"Database does not exist."}

Delete a CouchDB Database in the Fauxton Web Interface

You can also delete database in CouchDB using Web Interface.

Open URL http://hostname/_utils/ in your browser. In this example, the URL will be http://127.0.0.1:5984/_utils/.

If authentication is enabled, sign in with an account that has permission to delete databases.

In this example, we will delete the database named mobiles.

Under Databases tab, click on the delete icon shown against the database to be deleted. The delete icon is marked in the following screenshot.

CouchDB - Delete Database

Once you click on the Delete button, you will be asked to confirm deletion as shown below. Enter the database name. Delete Database button will be enabled. Click on this button.

CouchDB - Delete Database - Confirm Deletion

After you click on the Delete Database button, you should see a message that the database has been deleted, as shown in the following picture.

CouchDB - Database Deleted

CouchDB Database Deletion Safety Checks

  • Confirm that the URL contains the intended database name.
  • Check whether applications are still reading from or writing to the database.
  • Create a backup or replication copy when the data may be required later.
  • Verify that you are connected to the correct CouchDB server and environment.
  • Use a GET request before deletion to inspect the target database.

These checks are especially important when development, testing and production CouchDB servers use similar database names.

Common CouchDB Delete Database Errors

CouchDB Database Does Not Exist

If the requested database is already absent or its name is incorrect, CouchDB returns a not-found response. Check the spelling and list the available databases before trying again.

</>
Copy
curl http://127.0.0.1:5984/_all_dbs

Unauthorized or Forbidden Database Deletion

An unauthorized or forbidden response means that the request does not have sufficient permission. Confirm the credentials and make sure the account is allowed to delete databases.

Unable to Connect to CouchDB on Port 5984

A connection error usually means CouchDB is not running, the hostname or port is incorrect, or access is blocked by a firewall or network configuration. Test the CouchDB server root URL before sending the delete request.

</>
Copy
curl http://127.0.0.1:5984/

Deleted the Wrong CouchDB Database

CouchDB does not provide an undo command for database deletion. Recovery requires a backup, replica or another copy of the data. Stop dependent applications from writing new data before restoring the database.

CouchDB Delete Database FAQs

Which HTTP method deletes a CouchDB database?

Use an HTTP DELETE request with the database URL, such as http://127.0.0.1:5984/cars.

Does deleting a CouchDB database remove all documents?

Yes. Deleting a database removes the database and all documents stored in it. Delete individual documents instead when the database itself must remain available.

Can a deleted CouchDB database be restored?

A deleted database can be restored only when a usable backup, replica or external copy exists. CouchDB does not include a recycle bin for deleted databases.

How do I confirm that a CouchDB database was deleted?

Send a GET request to the former database URL or check the Fauxton database list. A not-found response confirms that the database is no longer present.

CouchDB Database Deletion Summary

In this CouchDB Tutorial, we learned to delete a database via HTTP REST API and Web Interface provided by CouchDB. The REST API uses an HTTP DELETE request, while Fauxton provides a browser-based confirmation process. After deletion, use a GET request or inspect the Fauxton database list to verify that the database is no longer available.