A newer version of this documentation is available.

View Latest
February 16, 2025
+ 12

How to delete documents in Couchbase.
This guide is for Couchbase Server.

Introduction

In situations where data is no longer needed, Couchbase Server provides a remove operation to delete a document from the database permanently.

Read the following for further information about the clients available:

Please note that the examples in this guide will alter the data in your sample database. To restore your sample data, remove and reinstall the travel sample data. Refer to Sample Buckets for details.

Deleting a Document

To delete a specific field within a document, perform a Sub-Document remove operation.

Use the cbc rm command to delete a document from the database.


The example below deletes document airport_1254 from the database.

cbc rm -u Administrator -P password -U couchbase://localhost/travel-sample airport_1254
Result
console
airport_1254 Deleted

For further details, refer to cbc(1).

Deleting a Sub-Document

To delete a specific field within a document you can perform a Sub-Document remove operation.

  1. Connect to the cbc-subdoc interactive shell.

  2. Use the remove command to delete a field from a document.

  3. Pass the field to remove with the --path argument.


The example below deletes the url field from document hotel-123.

console
cbc-subdoc -u Administrator -P password -U couchbase://localhost/travel-sample subdoc> remove hotel-123 --path url
Result
console
hotel-123 CAS=0x16be2f11c6040000 0. Size=0, RC=LCB_SUCCESS (0)
If the path cannot be found, cbc-subdoc will return a LCB_ERR_SUBDOC_PATH_NOT_FOUND error.

For further details, refer to cbc-subdoc(1).

Key-Value Operations with SDKs:

Sub-Document operations with SDKs: