Delete rows reference

This Astra DB Serverless feature is currently in public preview. Development is ongoing, and the features and functionality are subject to change. Astra DB Serverless, and the use of such, is subject to the DataStax Preview Terms.

The Data API tables commands are available through HTTP and the clients.

If you use a client, tables commands are available only in client versions 2.0-preview or later. For more information, see Data API client upgrade guide.

A row represents a single record of data in a table in an Astra DB Serverless database.

You use the Table class to work with rows through the Data API clients. For instructions to get a Table object, see Work with tables.

For general information about working with rows, including common operations and operators, see Work with rows.

For more information about the Data API and clients, see Get started with the Data API.

Delete a row

Find and delete one row in a table.

  • Python

  • TypeScript

  • Java

  • curl

For more information, see the Client reference.

Find a row by its primary key, and then delete it:

my_table.delete_one({"match_id": "fight7", "round": 2})

Parameters:

Name Type Summary

filter

dict

Describes the full primary key of the row. The row matching that primary key will be deleted.

Only the the $eq operator is allowed in delete_one.

general_method_timeout_ms

int | None

A timeout, in milliseconds, to impose on the underlying API request. If not provided, the Table defaults apply. This parameter is aliased as request_timeout_ms and timeout_ms for convenience.

Full example script
from astrapy import DataAPIClient
client = DataAPIClient("TOKEN")
database = client.get_database("API_ENDPOINT")

from astrapy.constants import SortMode
from astrapy.info import (
    CreateTableDefinition,
    ColumnType,
)

my_table = database.create_table(
    "games",
    definition=(
        CreateTableDefinition.builder()
        .add_column("match_id", ColumnType.TEXT)
        .add_column("round", ColumnType.TINYINT)
        .add_vector_column("m_vector", dimension=3)
        .add_column("score", ColumnType.INT)
        .add_column("when", ColumnType.TIMESTAMP)
        .add_column("winner", ColumnType.TEXT)
        .add_set_column("fighters", ColumnType.UUID)
        .add_partition_by(["match_id"])
        .add_partition_sort({"round": SortMode.ASCENDING})
        .build()
    ),
)

insert_result = my_table.insert_many(
    [
        {"match_id": "fight7", "round": 1, "winner": "Joy"},
        {"match_id": "fight7", "round": 2, "winner": "Kevin"},
        {"match_id": "fight7", "round": 3, "winner": "Lauretta"},
    ],
)

# Count the rows matching a certain filter
len(my_table.find({"match_id": "fight7"}).to_list())
# 3

# Delete a row belonging to the group
my_table.delete_one({"match_id": "fight7", "round": 2})

# Count again
len(my_table.find({"match_id": "fight7"}).to_list())
# 2

# Attempt the delete again (nothing to delete)
my_table.delete_one({"match_id": "fight7", "round": 2})

# The count is unchanged
len(my_table.find({"match_id": "fight7"}).to_list())
# 2

Example:

# Count the rows matching a certain filter
len(my_table.find({"match_id": "fight7"}).to_list())
# 3

# Delete a row belonging to the group
my_table.delete_one({"match_id": "fight7", "round": 2})

# Count again
len(my_table.find({"match_id": "fight7"}).to_list())
# 2

# Attempt the delete again (nothing to delete)
my_table.delete_one({"match_id": "fight7", "round": 2})

# The count is unchanged
len(my_table.find({"match_id": "fight7"}).to_list())
# 2

For more information, see the Client reference.

Find a row by its primary key, and then delete it:

await table.deleteOne({ matchId: 'fight7', round: 2 });

Parameters:

Name Type Summary

filter

TableFilter

Describes the full primary key of the row. The row matching that primary key will be deleted.

Only the the $eq operator is allowed in deleteOne.

timeout?

WithTimeout

The client-side timeout for this operation.

Returns:

Promise<void> - A promise that resolves when the operation is complete.

Why void?

The deleteMany operation, as returned from the Data API, is always { deletedCount: -1 }, regardless of how many rows were deleted. Therefore, void is used.

Example:

Full script
import { CreateTableDefinition, DataAPIClient, InferTablePrimaryKey, InferTableSchema, timestamp, uuid, vector } from '@datastax/astra-db-ts';

// Instantiate the client and connect to the database
const client = new DataAPIClient();
const db = client.db(process.env.CLIENT_DB_URL!, { token: process.env.CLIENT_DB_TOKEN! });

// Create table schema using bespoke Data API table definition syntax, and then infer the type.
// For information about table typing and definitions, see the documentation for createTable.
const TableDefinition = <const>{
  columns: {
    matchId: 'text'
    round: 'tinyint',
    mVector: { type: 'vector', dimension: 3 },
    score: 'int',
    when: 'timestamp',
    winner: 'text',
    fighters: { type: 'set', valueType: 'uuid' },
  },
  primaryKey: {
    partitionBy: ['matchId'],
    partitionSort: { round: 1 },
  },
} satisfies CreateTableDefinition;

type TableSchema = InferTableSchema<typeof TableDefinition>;

(async function () {
  // Create a table with the given TableSchema type if a 'games' table doesn't already exist
  const table = await db.createTable<TableSchema>('games', { definition: TableDefinition, ifNotExists: true });

  // Insert some rows in an unordered fashion.
  await table.insertMany([
    { matchId: 'fight4', round: 1, winner: 'Victor' },
    { matchId: 'fight5', round: 1, winner: 'Adam' },
    { matchId: 'fight5', round: 2, winner: 'Betta' },
    { matchId: 'fight5', round: 3, winner: 'Caio' },
    { matchId: 'fight7', round: 1, winner: 'Joy' },
    { matchId: 'fight7', round: 2, winner: 'Kevin' },
    { matchId: 'fight7', round: 3, winner: 'Lauretta' },
  ]);

// Use deleteOne and deleteMany to remove rows from a table.

// deleteOne examples (with 'find' to demonstrate that the row was deleted)

  // Find rows where 'matchId' is 'fight7'
  await table.find({ matchId: 'fight7' }).toArray().then(rs => console.log(rs.length));

  // Delete one of the 'fight7' rows
  await table.deleteOne({ matchId: 'fight7', round: 2 });

  // Find the 'fight7' rows again
  // The deleted row should not be returned
  await table.find({ matchId: 'fight7' }).toArray().then(rs => console.log(rs.length));

  // Attempt to delete the same 'fight7' row again
  // Although the operation succeeds, nothing happens if the row was already deleted
  await table.deleteOne({ matchId: 'fight7', round: 2 });

  // Find the 'fight7' rows once again
  // The same rows are returned as the previous attempt because the row was already deleted
  await table.find({ matchId: 'fight7' }).toArray().then(rs => console.log(rs.length));

// deleteMany examples

  // To use deleteMany to delete one row, specify the full primary key
  await table.deleteMany({ matchId: 'fight4', round: 1 });

  // To delete part of a partition, use an inequality operator on the table's final 'partitionSort' column
  // This example deletes all rows where 'matchId' is 'fight5' and 'round' is greater than or equal to 5
  await table.deleteMany({ matchId: 'fight5', round: { $gte: 5 } });

  // To delete an entire partition, do not specify 'partitionSort' columns
  // This example deletes all rows where 'matchId' is 'fight6'
  await table.deleteMany({ matchId: 'fight7' });

  // To delete all rows in the table, pass an empty filter
  await table.deleteMany({});

  // Uncomment the following line to drop the table and any related indexes.
  // await table.drop();
})();
// Find rows where 'matchId' is 'fight7'
await table.find({ matchId: 'fight7' }).toArray().then(rs => console.log(rs.length));

// Delete one of the 'fight7' rows
await table.deleteOne({ matchId: 'fight7', round: 2 });

// Find the 'fight7' rows again
// The deleted row should not be returned
await table.find({ matchId: 'fight7' }).toArray().then(rs => console.log(rs.length));

// Attempt to delete the same 'fight7' row again
// Although the operation succeeds, nothing happens if the row was already deleted
await table.deleteOne({ matchId: 'fight7', round: 2 });

// Find the 'fight7' rows once again
// The same rows are returned as the previous attempt because the row was already deleted
await table.find({ matchId: 'fight7' }).toArray().then(rs => console.log(rs.length));

For more information, see the Client reference.

Find a row by its primary key, and then delete it:

Filter filter = and(
   eq("match_id", "fight7"),
   eq("round", 2));

// No options
tableRow.deleteOne(filter);

// Using Options
tableRow.deleteOne(filter, new TableDeleteOneOptions()
  .timeout(1000));

Parameters:

Name Type Summary

filter

Filter

Describes the row to delete by its primary key values.

You cannot filter on non-primary keys.

Only the the $eq operator is allowed in deleteOne.

Filters can be instantiated with its constructor and specialized with method where(..) or leverage the class Filters

options

TableDeleteOneOptions

Operations to be applied to the delete operation like (mostly) timeout.

Example:

package com.datastax.astra.client.tables;

import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.DataAPIClients;
import com.datastax.astra.client.core.query.Filter;
import com.datastax.astra.client.databases.Database;
import com.datastax.astra.client.tables.commands.TableUpdateOperation;
import com.datastax.astra.client.tables.commands.options.TableDeleteOneOptions;
import com.datastax.astra.client.tables.commands.options.TableUpdateOneOptions;
import com.datastax.astra.client.tables.definition.rows.Row;

import java.util.Set;

import static com.datastax.astra.client.core.query.Filters.and;
import static com.datastax.astra.client.core.query.Filters.eq;

public class DeleteOne {
 public static void main(String[] args) {
  Database db = new DataAPIClient("token").getDatabase("endpoint");

  Table<Row> tableRow = db.getTable("games");

  // Update
  Filter filter = and(
    eq("match_id", "fight7"),
    eq("round", 2));

  tableRow.deleteOne(filter);
  tableRow.deleteOne(filter, new TableDeleteOneOptions()
          .timeout(1000));

 }

}

Find a row by its primary key, and then delete it:

curl -sS -L -X POST "ASTRA_DB_API_ENDPOINT/api/json/v1/ASTRA_DB_KEYSPACE/ASTRA_DB_TABLE" \
--header "Token: ASTRA_DB_APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
  "deleteOne": {
    "filter": {
      "PRIMARY_KEY_COLUMN": "PRIMARY_KEY_VALUE"
    }
  }
}' | jq

Parameters:

Name Type Summary

deleteOne

command

The Data API command to find and delete the first row in a table that matches the given filter criteria. If there is no match, then no action is taken.

filter

object

Key-value pairs describing the full primary key of the row to delete.

Only the the $eq operator is allowed in deleteOne.

Returns:

A well-formed request returns "deletedCount": -1, regardless of whether a row was found or deleted. A well-formed request against an empty table still returns "deletedCount": -1.

Example response
{
  "status": {
    "deletedCount": -1
  }
}

Delete rows

Delete multiple rows in a table.

  • Python

  • TypeScript

  • Java

  • curl

For more information, see the Client reference.

Delete one single row (by specifying a full primary key):

my_table.delete_many({"match_id": "fight4", "round": 1})

Delete part of a partition (by specifying a range within a partition):

my_table.delete_many({"match_id": "fight5", "round": {"$gte": 5}})

Delete a whole partition (by specifying the "partitionBy" column values):

my_table.delete_many({"match_id": "fight7"})

An empty filter deletes all rows and completely empties the table:

my_table.delete_many({})

Parameters:

Name Type Summary

filter

dict

A filter dictionary to specify the rows to delete.

  • If the filter is in the form {"primary_key_1": value1, "primary_key_2": value2 …​} and specifies the primary key in full, only the row matching that full primary key will be deleted.

  • If the table has partitionSort columns, some or all of them may be omitted from the filter. If there are multiple partitionSort, you can use the $eq, $ne, or range operators (such as $gt) on the last partitionSort column. A range of rows, always within a single partition, will be deleted.

  • If an empty filter, {}, is passed, this operation empties the table completely.

    An empty filter deletes all rows, completely emptying the table.

  • Other kinds of filtering clauses are forbidden.

delete_many filter examples

For example, if a table is partitioned by columns ["partition_key1", "partition_key2"] and has partition sort of "partition_sort1" and "partition_sort2" in that order:

  • {"partition_key1": x, "partition_key2": y, "partition_sort1": z, "partition_sort2": t}: deletes one row

  • {"partition_key1": x, "partition_key2": y, "partition_sort1": z}: deletes multiple rows

  • {"partition_key1": x, "partition_key2": y, "partition_sort1": z, "partition_sort2": {"$lt": q}}: deletes multiple rows

  • {"partition_key1": x, "partition_key2": y}: deletes all rows in the partition

  • {}: empties the table

Invalid filter examples:

  • {"partition_key1": x}: incomplete partition key

  • {"partition_key1": x, "partition_sort1" z}: incomplete partition key

  • {"partition_key1": x, "partition_key2": y, "partition_sort1": {"$lt": r}, "partition_sort2": t}: inequality on a non-least-significant partition sort column

  • {"partition_key1": x, "partition_key2": y, "partition_sort2": t}: cannot skip partition_sort1

For information about operators, see Data API operators.

general_method_timeout_ms

int | None

A timeout, in milliseconds, to impose on the underlying API request. If not provided, the Table defaults apply. This parameter is aliased as request_timeout_ms and timeout_ms for convenience.

Example:

Full script
from astrapy import DataAPIClient
client = DataAPIClient("TOKEN")
database = client.get_database("API_ENDPOINT")

from astrapy.constants import SortMode
from astrapy.info import (
    CreateTableDefinition,
    ColumnType,
)

my_table = database.create_table(
    "games",
    definition=(
        CreateTableDefinition.builder()
        .add_column("match_id", ColumnType.TEXT)
        .add_column("round", ColumnType.TINYINT)
        .add_vector_column("m_vector", dimension=3)
        .add_column("score", ColumnType.INT)
        .add_column("when", ColumnType.TIMESTAMP)
        .add_column("winner", ColumnType.TEXT)
        .add_set_column("fighters", ColumnType.UUID)
        .add_partition_by(["match_id"])
        .add_partition_sort({"round": SortMode.ASCENDING})
        .build()
    ),
)

from astrapy.data_types import (
    DataAPISet,
    DataAPITimestamp,
    DataAPIVector,
)
from astrapy.ids import UUID

insert_result = my_table.insert_many(
    [
        {
            "match_id": "fight4",
            "round": 1,
            "winner": "Victor",
            "score": 18,
            "when": DataAPITimestamp.from_string(
                "2024-11-28T11:30:00Z",
            ),
            "fighters": DataAPISet([
                UUID("0193539a-2770-8c09-a32a-111111111111"),
                UUID('019353e3-00b4-83f9-a127-222222222222'),
            ]),
            "m_vector": DataAPIVector([0.4, -0.6, 0.2]),
        },
        {"match_id": "fight5", "round": 1, "winner": "Adam"},
        {"match_id": "fight5", "round": 2, "winner": "Betta"},
        {"match_id": "fight5", "round": 3, "winner": "Caio"},
        {"match_id": "fight7", "round": 1, "winner": "Joy"},
        {"match_id": "fight7", "round": 2, "winner": "Kevin"},
        {"match_id": "fight7", "round": 3, "winner": "Lauretta"},
    ],
)

# Delete a single row (full primary key specified):
my_table.delete_many({"match_id": "fight4", "round": 1})

# Delete part of a partition (inequality on the
# last-mentioned 'partitionSort' column):
my_table.delete_many({"match_id": "fight5", "round": {"$gte": 5}})

# Delete a whole partition (leave 'partitionSort' unspecified):
my_table.delete_many({"match_id": "fight7"})

# empty the table entirely with empty filter (CAUTION):
my_table.delete_many({})
# Delete a single row (full primary key specified):
my_table.delete_many({"match_id": "fight4", "round": 1})

# Delete part of a partition (inequality on the
# last-mentioned 'partitionSort' column):
my_table.delete_many({"match_id": "fight5", "round": {"$gte": 5}})

# Delete a whole partition (leave 'partitionSort' unspecified):
my_table.delete_many({"match_id": "fight7"})

# empty the table entirely with empty filter (CAUTION):
my_table.delete_many({})

Use this command to delete multiple rows from a table based on filter conditions.

Unlike collections, this operation is not paginated. All rows that match the filter are deleted in a single operation.

For more information, see the Client reference.

Delete one single row (by specifying a full primary key):

await table.deleteMany({ matchId: 'fight4', round: 1 });

Delete part of a partition (by specifying a range within a partition):

await table.deleteMany({ matchId: 'fight5', round: { $gte: 5 } });

Delete a whole partition (by specifying the "partitionBy" column values):

await table.deleteMany({ matchId: 'fight7' });

An empty filter deletes all rows and completely empties the table:

await table.deleteMany({});

Parameters:

Name Type Summary

filter

TableFilter

An object containing the filter to apply to the table to determine which rows to delete.

It can be empty or contain key-value pairs that determine the rows to delete.

An empty filter deletes all rows, completely emptying the table.

If not empty, the contents of filter depends on the table’s primary key definition:

  • For single-column primary keys, filter must include the primary key, and it cannot include any other columns.

  • For composite primary keys, filter must include all partition keys, and it cannot include any columns outside of the primary key definition.

  • For compound primary keys, filter must include all partition keys. It can include optional clustering keys, but it cannot include columns outside of the primary key definition.

    If you include clustering keys, you must include them in the order specified in the primary key definition. You can omit clustering keys, but you can’t skip any clustering keys. For example, if you have three clustering keys, a, b, and c, then you can include a and omit b and c. However, if you include b, then you must also include a.

    Additionally, clustering keys allow only the $eq operator, with the exception of the last clustering key in the table’s primary key definition, which allows $eq, $ne, or range operators ($gt, $gte, $lt, and $lte). For example, if your table has three clustering keys, a, b, and c, then you can only use range operators with c.

For information about operators, see Data API operators.

timeout?

WithTimeout

The client-side timeout for this operation.

Returns:

Promise<void> - A promise that resolves when the operation is complete.

Why void?

The deleteMany operation, as returned from the Data API, is always { deletedCount: -1 }, regardless of how many rows were deleted. Therefore, void is used.

Example:

Full script
import { CreateTableDefinition, DataAPIClient, InferTablePrimaryKey, InferTableSchema, timestamp, uuid, vector } from '@datastax/astra-db-ts';

// Instantiate the client and connect to the database
const client = new DataAPIClient();
const db = client.db(process.env.CLIENT_DB_URL!, { token: process.env.CLIENT_DB_TOKEN! });

// Create table schema using bespoke Data API table definition syntax, and then infer the type.
// For information about table typing and definitions, see the documentation for createTable.
const TableDefinition = <const>{
  columns: {
    matchId: 'text'
    round: 'tinyint',
    mVector: { type: 'vector', dimension: 3 },
    score: 'int',
    when: 'timestamp',
    winner: 'text',
    fighters: { type: 'set', valueType: 'uuid' },
  },
  primaryKey: {
    partitionBy: ['matchId'],
    partitionSort: { round: 1 },
  },
} satisfies CreateTableDefinition;

type TableSchema = InferTableSchema<typeof TableDefinition>;

(async function () {
  // Create a table with the given TableSchema type if a 'games' table doesn't already exist
  const table = await db.createTable<TableSchema>('games', { definition: TableDefinition, ifNotExists: true });

  // Insert some rows in an unordered fashion.
  await table.insertMany([
    { matchId: 'fight4', round: 1, winner: 'Victor' },
    { matchId: 'fight5', round: 1, winner: 'Adam' },
    { matchId: 'fight5', round: 2, winner: 'Betta' },
    { matchId: 'fight5', round: 3, winner: 'Caio' },
    { matchId: 'fight7', round: 1, winner: 'Joy' },
    { matchId: 'fight7', round: 2, winner: 'Kevin' },
    { matchId: 'fight7', round: 3, winner: 'Lauretta' },
  ]);

// Use deleteOne and deleteMany to remove rows from a table.

// deleteOne examples (with 'find' to demonstrate that the row was deleted)

  // Find rows where 'matchId' is 'fight7'
  await table.find({ matchId: 'fight7' }).toArray().then(rs => console.log(rs.length));

  // Delete one of the 'fight7' rows
  await table.deleteOne({ matchId: 'fight7', round: 2 });

  // Find the 'fight7' rows again
  // The deleted row should not be returned
  await table.find({ matchId: 'fight7' }).toArray().then(rs => console.log(rs.length));

  // Attempt to delete the same 'fight7' row again
  // Although the operation succeeds, nothing happens if the row was already deleted
  await table.deleteOne({ matchId: 'fight7', round: 2 });

  // Find the 'fight7' rows once again
  // The same rows are returned as the previous attempt because the row was already deleted
  await table.find({ matchId: 'fight7' }).toArray().then(rs => console.log(rs.length));

// deleteMany examples

  // To use deleteMany to delete one row, specify the full primary key
  await table.deleteMany({ matchId: 'fight4', round: 1 });

  // To delete part of a partition, use an inequality operator on the table's final 'partitionSort' column
  // This example deletes all rows where 'matchId' is 'fight5' and 'round' is greater than or equal to 5
  await table.deleteMany({ matchId: 'fight5', round: { $gte: 5 } });

  // To delete an entire partition, do not specify 'partitionSort' columns
  // This example deletes all rows where 'matchId' is 'fight6'
  await table.deleteMany({ matchId: 'fight7' });

  // To delete all rows in the table, pass an empty filter
  await table.deleteMany({});

  // Uncomment the following line to drop the table and any related indexes.
  // await table.drop();
})();
// To use deleteMany to delete one row, specify the full primary key
await table.deleteMany({ matchId: 'fight4', round: 1 });

// To delete part of a partition, use an inequality operator on the table's final 'partitionSort' column
// This example deletes all rows where 'matchId' is 'fight5' and 'round' is greater than or equal to 5
await table.deleteMany({ matchId: 'fight5', round: { $gte: 5 } });

// To delete an entire partition, do not specify 'partitionSort' columns
// This example deletes all rows where 'matchId' is 'fight6'
await table.deleteMany({ matchId: 'fight7' });

// To delete all rows in the table, pass an empty filter
await table.deleteMany({});

For more information, see the Client reference.

Delete one single row (by specifying a full primary key):

Filter filter =
  and(eq("match_id", "fight7"), eq("round", 2));
tableRow.deleteMany(filter);

Delete part of a partition (by specifying a range within a partition):

Filter filter2 =
 and(eq("match_id", "fight5"), gte("round", 5));
tableRow.deleteMany(filter2);

Delete a whole partition (by specifying the "partitionBy" column values):

tableRow
  .deleteMany(eq("match_id", "fight5"));

An empty filter deletes all rows and completely empties the table.

Additionally, you can use the syntactic sugar method, deleteAll, to delete all rows in a table. The 3 following commands are equivalent:

myTable.deleteMany(null);
myTable.deleteMany(new Filter());
myTable.deleteAll();

Parameters:

Name Type Summary

filter

Filter

A filter expressing which condition the returned row must satisfy, which can be empty or use operators to compare columns with literal values. Filters can be instantiated with its constructor and specialized with method where(..) or leverage the class Filters

If not empty, the contents of filter depends on the table’s primary key definition:

* For single-column primary keys, filter must include the primary key, and it cannot include any other columns. * For composite primary keys, filter must include all partition keys, and it cannot include any columns outside of the primary key definition. * For compound primary keys, filter must include all partition keys. It can include optional clustering keys, but it cannot include columns outside of the primary key definition. + If you include clustering keys, you must include them in the order specified in the primary key definition. You can omit clustering keys, but you can’t skip any clustering keys. For example, if you have three clustering keys, a, b, and c, then you can include a and omit b and c. However, if you include b, then you must also include a. + Additionally, clustering keys allow only the $eq operator, with the exception of the last clustering key in the table’s primary key definition, which allows $eq, $ne, or range operators ($gt, $gte, $lt, and $lte). For example, if your table has three clustering keys, a, b, and c, then you can only use range operators with c.

For information about operators, see Data API operators.

options

TableDeleteManyOptions

Operations to be applied to the delete operation like (mostly) timeout.

Example:

package com.datastax.astra.client.tables;

import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.DataAPIClients;
import com.datastax.astra.client.core.query.Filter;
import com.datastax.astra.client.databases.Database;
import com.datastax.astra.client.tables.commands.options.TableDeleteManyOptions;
import com.datastax.astra.client.tables.commands.options.TableDeleteOneOptions;
import com.datastax.astra.client.tables.definition.rows.Row;

import static com.datastax.astra.client.core.query.Filters.and;
import static com.datastax.astra.client.core.query.Filters.eq;
import static com.datastax.astra.client.core.query.Filters.gte;

public class DeleteMany {
 public static void main(String[] args) {
  Database db = new DataAPIClient("token").getDatabase("endpoint");

  Table<Row> tableRow = db.getTable("games");

  // Update
  Filter filter = and(
    eq("match_id", "fight7"),
    eq("round", 2));

  tableRow.deleteMany(filter);
  tableRow.deleteMany(filter, new TableDeleteManyOptions()
          .timeout(1000));

  Filter filter2 = and(
          eq("match_id", "fight5"),
          gte("round", 5));
  tableRow.deleteMany(filter2);

 }

}

Find rows matching a given filter, and then delete them:

curl -sS -L -X POST "ASTRA_DB_API_ENDPOINT/api/json/v1/ASTRA_DB_KEYSPACE/ASTRA_DB_TABLE" \
--header "Token: ASTRA_DB_APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
  "deleteMany": {
    "filter": {
      "FILTER_COLUMN": "FILTER_VALUE",
      "FILTER_COLUMN": "FILTER_VALUE"
    }
  }
}' | jq

An empty filter or empty deleteMany object deletes all rows and completely empties the table:

# Empty filter object deletes all rows
"deleteMany": { "filter": {} }

# Empty deleteMany object deletes all rows
"deleteMany": {}

Parameters:

Name Type Summary

deleteMany

command

The Data API command to delete any rows in a table that match a given filter.

filter

object

Can be empty or contain key-value pairs that determine the rows to delete.

An empty filter deletes all rows, completely emptying the table.

If not empty, the contents of filter depends on the table’s primary key definition:

  • For single-column primary keys, filter must include the primary key, and it cannot include any other columns.

  • For composite primary keys, filter must include all partition keys, and it cannot include any columns outside of the primary key definition.

  • For compound primary keys, filter must include all partition keys. It can include optional clustering keys, but it cannot include columns outside of the primary key definition.

    If you include clustering keys, you must include them in the order specified in the primary key definition. You can omit clustering keys, but you can’t skip any clustering keys. For example, if you have three clustering keys, a, b, and c, then you can include a and omit b and c. However, if you include b, then you must also include a.

    Additionally, clustering keys allow only the $eq operator, with the exception of the last clustering key in the table’s primary key definition, which allows $eq, $ne, or range operators ($gt, $gte, $lt, and $lte). For example, if your table has three clustering keys, a, b, and c, then you can only use range operators with c.

For information about operators, see Data API operators.

Returns:

A well-formed request returns "deletedCount": -1, regardless of the number of rows actually deleted. A well-formed request against an empty table still returns "deletedCount": -1.

deleteMany does not paginate the response. If any rows matched the given filter, they are deleted in a single operation.

Example response
{
  "status": {
    "deletedCount": -1
  }
}

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2024 DataStax | Privacy policy | Terms of use

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com