Delete a row (TypeScript)
Finds a single row in a table using filter clauses, and then deletes that row.
Deleting rows produces tombstones. Excessive tombstones can impact query performance.
For general information about working with tables and rows, see About tables with the Data API (TypeScript).
|
Ready to write code? See the examples for this method to get started. If you are new to the Data API, check out the quickstart. |
Result
Deletes a row that matches the specified parameters. If no rows match the specified parameters, this method does not delete any rows.
Returns a promise that resolves once the operation completes.
Parameters
Use the deleteOne method, which belongs to the Table class.
Method signature
async deleteOne(
filter: TableFilter<Schema>,
options?: {
timeout?: number | TimeoutDescriptor,
},
): void
| Name | Type | Summary |
|---|---|---|
|
|
Describes the full primary key of the row to delete. For this method, the filter can only use the |
|
|
Optional. A timeout to impose on the underlying API request. |
Examples
The following examples demonstrate how to delete a row in a table.
Delete a row by primary key
You can filter by primary key to find and delete a row. The filter must describe the full primary key and cannot include any other columns.
import {
DataAPIClient,
UsernamePasswordTokenProvider,
} from "@datastax/astra-db-ts";
// Get an existing table
const client = new DataAPIClient({ environment: "hcd" });
const database = client.db("API_ENDPOINT", {
token: new UsernamePasswordTokenProvider("USERNAME", "PASSWORD"),
keyspace: "KEYSPACE_NAME",
});
const table = database.table("TABLE_NAME");
// Delete a row
(async function () {
const result = await table.deleteOne({
title: "Hidden Shadows of the Past",
author: "John Anthony",
});
console.log(result);
})();
Client reference
For more information, see the client reference.