Update a row

Tables with the Data API are 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.

Updates a single row in a table.

If the row does not already exist and the update includes at least one non-null or non-empty value, creates a new row.

For general information about working with tables and rows, see About tables with the Data API.

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

  • Python

  • TypeScript

  • Java

  • curl

Updates the specified row.

If no row matches the specified primary key and the update includes at least one non-null or non-empty value, then a new row is created with the values specified $set values and primary key values. Any omitted or $unset columns are set to null in the new row.

Does not return anything.

A rare edge case, related to underlying Apache Cassandra® functionality, can cause rows to disappear altogether when all of its columns are set to null.

This happens if the row was previously created from an update operation that had no pre-existing row to modify.

Updates the specified row.

If no row matches the specified primary key and the update includes at least one non-null or non-empty value, then a new row is created with the values specified $set values and primary key values. Any omitted or $unset columns are set to null in the new row.

Returns a promise that resolves once the operation completes.

A rare edge case, related to underlying Apache Cassandra® functionality, can cause rows to disappear altogether when all of its columns are set to null.

This happens if the row was previously created from an update operation that had no pre-existing row to modify.

Updates the specified row.

If no row matches the specified primary key and the update includes at least one non-null or non-empty value, then a new row is created with the values specified $set values and primary key values. Any omitted or $unset columns are set to null in the new row.

Does not return anything.

A rare edge case, related to underlying Apache Cassandra® functionality, can cause rows to disappear altogether when all of its columns are set to null.

This happens if the row was previously created from an update operation that had no pre-existing row to modify.

Updates the specified row.

If no row matches the specified primary key and the update includes at least one non-null or non-empty value, then a new row is created with the values specified $set values and primary key values. Any omitted or $unset columns are set to null in the new row.

A rare edge case, related to underlying Apache Cassandra® functionality, can cause rows to disappear altogether when all of its columns are set to null.

This happens if the row was previously created from an update operation that had no pre-existing row to modify.

Always returns a status.matchedCount of 1, a status.modifiedCount of 1, and a status.upsertCount of 0, regardless of the outcome.

Example response:

{
  "status": {
    "matchedCount": 1,
    "modifiedCount": 1,
    "upsertCount": 0
  }
}

Parameters

  • Python

  • TypeScript

  • Java

  • curl

Use the update_one method, which belongs to the astrapy.Table class.

Method signature
update_one(
  filter: Dict[str, Any],
  update: Dict[str, Any],
  *,
  general_method_timeout_ms: int,
  request_timeout_ms: int,
  timeout_ms: int,
) -> None
Name Type Summary

filter

dict

Describes the row to update (or upsert) by its primary key values.

You cannot filter on non-primary keys.

Only the $eq operator is allowed.

update

dict

The update to apply to the row.

For allowed operators, see Update operators for tables.

You cannot use update_one to modify primary key values. If you need to modify a row’s primary key, you must delete the row and then insert a new row with the desired primary key values.

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.

Use the updateOne method, which belongs to the Table class.

Method signature
async updateOne(
  filter: TableFilter<Schema>,
  update: TableUpdateFilter<Schema>,
  options?: {
    timeout?: number | TimeoutDescriptor,
  },
): void
Name Type Summary

filter

TableFilter

Describes the row to update (or upsert) by its primary key values.

You cannot filter on non-primary keys.

Only the $eq operator is allowed.

update

TableUpdateFilter

The update to apply to the row.

For allowed operators, see Update operators for tables.

You cannot use updateOne to modify primary key values. If you need to modify a row’s primary key, you must delete the row and then insert a new row with the desired primary key values.

options.timeout?

WithTimeout

The client-side timeout for this operation.

Use the updateOne method, which belongs to the com.datastax.astra.client.tables.Table class.

Method signature
void updateOne(
  Filter filter,
  TableUpdateOperation update
)
void updateOne(
  Filter filter,
  TableUpdateOperation update,
  TableUpdateOneOptions options
)
Name Type Summary

filter

Filter

Describes the row to update (or upsert) by its primary key values.

You cannot filter on non-primary keys.

Only the $eq operator is allowed.

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

operation

TableUpdateOperation

A wrapper for the different options and specialization of this search.

options

TableUpdateOneOptions

Operations to be applied to the update operation. It could be set or unset operations.

Method Summary

set(String column, Object value)

Set a column to a new value.

unset(String column, Object value)

Sets a given column’s value to null or the equivalent empty form, such as [] or {} for map, list, and set types.

unset(String…​ column)

Unset a list of columns.

Name Type Summary

timeout

long or Duration

Overrides the client-side timeout for this operation. If not provided, the Table defaults apply.

Use the updateOne command.

Command signature
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/TABLE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
  "updateOne": {
    "filter": FILTER,
    "update": UPDATE
  }
}'
Name Type Summary

updateOne

command

Data API command to update one row in a table.

filter

object

Describes the row to update (or upsert) by its primary key values.

You cannot filter on non-primary keys.

Only the $eq operator is allowed.

update

object

The update to apply to the row.

For allowed operators, see Update operators for tables.

You cannot use updateOne to modify primary key values. If you need to modify a row’s primary key, you must delete the row and then insert a new row with the desired primary key values.

Examples

The following examples demonstrate how to update a row in a table.

Update multiple columns

You can combine multiple operators and properties in a single call. For the full list of operators, see Update operators for tables.

If the row does not already exist and the update includes at least one non-null or non-empty value, creates a new row.

  • Python

  • TypeScript

  • Java

  • curl

from astrapy import DataAPIClient

# Get an existing table
client = DataAPIClient("APPLICATION_TOKEN")
database = client.get_database("API_ENDPOINT")
table = database.get_table("TABLE_NAME")

# Update a row
table.update_one(
    {"title": "Hidden Shadows of the Past", "author": "John Anthony"},
    {
        "$set": {"rating": 4.5, "genres": ["Fiction", "Drama"]},
        "$unset": {"borrower": ""},
    },
)
import { DataAPIClient } from "@datastax/astra-db-ts";

// Get an existing table
const client = new DataAPIClient("APPLICATION_TOKEN");
const database = client.db("API_ENDPOINT");
const table = database.table("TABLE_NAME");

// Update a row
(async function () {
  await table.updateOne(
    {
      title: "Hidden Shadows of the Past",
      author: "John Anthony",
    },
    {
      $set: {
        rating: 4.5,
        genres: ["Fiction", "Drama"],
      },
      $unset: {
        borrower: "",
      },
    },
  );
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.core.query.Filter;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.commands.TableUpdateOperation;
import com.datastax.astra.client.tables.definition.rows.Row;
import java.util.Arrays;
import java.util.Map;

public class Example {

  public static void main(String[] args) {
    // Get an existing table
    Table<Row> table =
        new DataAPIClient("APPLICATION_TOKEN")
            .getDatabase("API_ENDPOINT")
            .getTable("TABLE_NAME");

    // Update a row
    Filter filter =
        new Filter(
            Map.of(
                "title", "Hidden Shadows of the Past",
                "author", "John Anthony"));
    TableUpdateOperation update =
        new TableUpdateOperation()
            .set("rating", 4.5)
            .set("genres", Arrays.asList("Fiction", "Drama"))
            .unset("borrower");
    table.updateOne(filter, update);
  }
}
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/TABLE_NAME" \
  --header "Token: APPLICATION_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
  "updateOne": {
    "filter": {
      "title": "Hidden Shadows of the Past",
      "author": "John Anthony"
    },
    "update": {
        "$set": {
          "rating": 4.5,
          "genres": ["Fiction", "Drama"]
        },
        "$unset": {
            "borrower": ""
        }
    }
  }
}'

Update a map column

If the updated map includes non-string keys, you must use an array of key-value pairs to update the map column. Otherwise, you can use an array of key-value pairs or a normal map.

  • Python

  • TypeScript

  • Java

  • curl

With the Python client, you can also use DataAPIMap to encode maps that use non-string keys.

from astrapy import DataAPIClient
from astrapy.data_types import DataAPIMap

# Get an existing table
client = DataAPIClient("APPLICATION_TOKEN")
database = client.get_database("API_ENDPOINT")
table = database.get_table("TABLE_NAME")

# Update a row
table.update_one(
    {"title": "Hidden Shadows of the Past", "author": "John Anthony"},
    {
        "$set": {
            # This map has non-string keys,
            # so the update is an array of key-value pairs
            "map_column_1": [[1, "value1"], [2, "value2"]],
            # Alternatively, use DataAPIMap to encode maps with non-string keys
            "map_column_2": DataAPIMap({1: "value1", 2: "value2"}),
            # This map does not have non-string keys,
            # so the update does not need to be an array of key-value pairs
            "map_column_3": {"key1": "value1", "key2": "value2"},
        }
    },
)
import { DataAPIClient } from "@datastax/astra-db-ts";

// Get an existing table
const client = new DataAPIClient("APPLICATION_TOKEN");
const database = client.db("API_ENDPOINT");
const table = database.table("TABLE_NAME");

// Update a row
(async function () {
  await table.updateOne(
    {
      title: "Hidden Shadows of the Past",
      author: "John Anthony",
    },
    {
      $set: {
        // This map has non-string keys,
        // so the update is an array of key-value pairs
        map_column_1: [
          [1, "value1"],
          [2, "value2"],
        ],
        // This map does not have non-string keys,
        // so the update does not need to be an array of key-value pairs
        map_column_2: {
          key1: "value1",
          key2: "value2",
        },
      },
    },
  );
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.core.query.Filter;
import com.datastax.astra.client.core.query.Filters;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.commands.TableUpdateOperation;
import com.datastax.astra.client.tables.definition.rows.Row;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class Example {

  public static void main(String[] args) {
    // Get an existing table
    Table<Row> table =
        new DataAPIClient("APPLICATION_TOKEN")
            .getDatabase("API_ENDPOINT")
            .getTable("TABLE_NAME");

    Filter filter =
        Filters.and(
            Filters.eq("title", "Hidden Shadows of the Past"),
            Filters.eq("author", "John Anthony"));

    // This map has non-string keys,
    // so the update is an array of key-value pairs
    List<List<Object>> mapColumn1 =
        Arrays.asList(Arrays.asList(1, "value1"), Arrays.asList(2, "value2"));

    // This map does not have non-string keys,
    // so the update does not need to be an array of key-value pairs
    Map<String, String> mapColumn2 = Map.of("key1", "value1", "key2", "value2");

    TableUpdateOperation update =
        new TableUpdateOperation().set("map_column_1", mapColumn1).set("map_column_2", mapColumn2);

    table.updateOne(filter, update);
  }
}
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/TABLE_NAME" \
  --header "Token: APPLICATION_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
  "updateOne": {
    "filter": {
      "title": "Hidden Shadows of the Past",
      "author": "John Anthony"
    },
    "update": {
      "$set": {
        # This map has non-string keys,
        # so the update is an array of key-value pairs
        "map_column_1": [
            [1, "value1"],
            [2, "value2"]
        ],
        # This map does not have non-string keys,
        # so the update does not need to be an array of key-value pairs
        "map_column_2": {
          "key1": "value1",
          "key2": "value2"
        }
      }
    }
  }
}'

Append to a list or set column

Use $push to append a single element to a list or set. Use $push with $each to append multiple elements.

  • Python

  • TypeScript

  • Java

  • curl

from astrapy import DataAPIClient

# Get an existing table
client = DataAPIClient("APPLICATION_TOKEN")
database = client.get_database("API_ENDPOINT")
table = database.get_table("TABLE_NAME")

# Update a row
table.update_one(
    {"title": "Hidden Shadows of the Past", "author": "John Anthony"},
    {
        "$push": {
            # Appends a single element to the "genres" list
            "genres": "SciFi",
            # Appends two elements to the "topics" list
            "topics": {"$each": ["robots", "AI"]},
        }
    },
)
import { DataAPIClient } from "@datastax/astra-db-ts";

// Get an existing table
const client = new DataAPIClient("APPLICATION_TOKEN");
const database = client.db("API_ENDPOINT");
const table = database.table("TABLE_NAME");

// Update a row
(async function () {
  await table.updateOne(
    {
      title: "Hidden Shadows of the Past",
      author: "John Anthony",
    },
    {
      $push: {
        // Appends a single element to the "genres" list
        genres: "SciFi",
        // Appends two elements to the "topics" list
        topics: {
          $each: ["robots", "AI"],
        },
      },
    },
  );
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.core.query.Filter;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.commands.TableUpdateOperation;
import com.datastax.astra.client.tables.definition.rows.Row;
import java.util.Arrays;
import java.util.Map;

public class Example {

  public static void main(String[] args) {
    // Get an existing table
    Table<Row> table =
        new DataAPIClient("APPLICATION_TOKEN")
            .getDatabase("API_ENDPOINT")
            .getTable("TABLE_NAME");

    // Update a row
    Filter filter =
        new Filter(
            Map.of(
                "title", "Hidden Shadows of the Past",
                "author", "John Anthony"));

    TableUpdateOperation update =
        new TableUpdateOperation(
            Map.of(
                "$push",
                Map.of(
                    // Appends a single element to the "genres" list
                    "genres",
                    "SciFi",
                    // Appends two elements to the "topics" list
                    "topics",
                    Map.of("$each", Arrays.asList("robots", "AI")))));

    table.updateOne(filter, update);
  }
}
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/TABLE_NAME" \
  --header "Token: APPLICATION_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
  "updateOne": {
    "filter": {
      "title": "Hidden Shadows of the Past",
      "author": "John Anthony"
    },
    "update": {
      "$push": {
        # Appends a single element to the "genres" list
        "genres": "SciFi",
        # Appends two elements to the "topics" list
        "topics": {
          "$each": ["robots", "AI"]
        }
      }
    }
  }
}'

Append to a map column

Use $push to append a single key-value pair to a map. Use $push with $each to append multiple key-value pairs.

If the appended key-value pair has a non-string key, you must represent the key-value pair as an array. Otherwise, you can either use an array or a normal map.

  • Python

  • TypeScript

  • Java

  • curl

from astrapy import DataAPIClient
from astrapy.data_types import DataAPIMap

# Get an existing table
client = DataAPIClient("APPLICATION_TOKEN")
database = client.get_database("API_ENDPOINT")
table = database.get_table("TABLE_NAME")

# Update a row
table.update_one(
    {"title": "Hidden Shadows of the Past", "author": "John Anthony"},
    {
        "$push": {
            # This update includes non-string keys,
            # so the update is a key-value pair represented as an array
            "map_column_1": [1, "value1"],
            # This update does not include non-string keys,
            # so the update can be a key-value pair represented as an array or a map
            "map_column_2": {"key1": "value1"},
            # When using $each, use an array of key-value pairs for non-string keys
            "map_column_3": {"$each": [[1, "value1"], [2, "value2"]]},
            # When using $each, use an array of key-value pairs or maps for string keys
            "map_column_4": {"$each": [{"key1": "value1"}, ["key2", "value2"]]},
        }
    },
)
import { DataAPIClient } from "@datastax/astra-db-ts";

// Get an existing table
const client = new DataAPIClient("APPLICATION_TOKEN");
const database = client.db("API_ENDPOINT");
const table = database.table("TABLE_NAME");

// Update a row
(async function () {
  await table.updateOne(
    {
      title: "Hidden Shadows of the Past",
      author: "John Anthony",
    },
    {
      $push: {
        // This update includes non-string keys,
        // so the update is a key-value pair represented as an array
        map_column_1: [1, "value1"],
        // This update does not include non-string keys,
        // so the update can be a key-value pair represented as an array or a map
        map_column_2: {
          key1: "value1",
        },
        // When using $each, use an array of key-value pairs for non-string keys
        map_column_3: {
          $each: [
            [1, "value1"],
            [2, "value2"],
          ],
        },
        // When using $each, use an array of key-value pairs or maps for string keys
        map_column_4: {
          $each: [{ key1: "value1" }, ["key2", "value2"]],
        },
      },
    },
  );
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.core.query.Filter;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.commands.TableUpdateOperation;
import com.datastax.astra.client.tables.definition.rows.Row;
import java.util.Arrays;
import java.util.Map;

public class Example {

  public static void main(String[] args) {
    // Get an existing table
    Table<Row> table =
        new DataAPIClient("APPLICATION_TOKEN")
            .getDatabase("API_ENDPOINT")
            .getTable("TABLE_NAME");

    // Update a row
    Filter filter =
        new Filter(
            Map.of(
                "title", "Hidden Shadows of the Past",
                "author", "John Anthony"));

    TableUpdateOperation update =
        new TableUpdateOperation(
            Map.of(
                "$push",
                Map.of(
                    // This update includes non-string keys,
                    // so the update is a key-value pair represented as an array
                    "map_column_1",
                    Arrays.asList(1, "value1"),
                    // This update does not include non-string keys,
                    // so the update can be a key-value pair represented as an array or a map
                    "map_column_2",
                    Map.of("key1", "value1"),
                    // When using $each, use an array of key-value pairs for non-string keys
                    "map_column_3",
                    Map.of(
                        "$each",
                        Arrays.asList(Arrays.asList(1, "value1"), Arrays.asList(2, "value2"))),
                    // When using $each, use an array of key-value pairs or maps for string keys
                    "map_column_4",
                    Map.of(
                        "$each",
                        Arrays.asList(
                            Map.of("key1", "value1"), Arrays.asList("key2", "value2"))))));

    table.updateOne(filter, update);
  }
}
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/TABLE_NAME" \
  --header "Token: APPLICATION_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
  "updateOne": {
    "filter": {
      "title": "Hidden Shadows of the Past",
      "author": "John Anthony"
    },
    "update": {
        "$push": {
          # This update includes non-string keys,
          # so the update is a key-value pair represented as an array
          "map_column_1": [
            1, "value1"
          ],
          # This update does not include non-string keys,
          # so the update can be a key-value pair represented as an array or a map
          "map_column_2": {
            "key1": "value1"
          },
          # When using $each, use an array of key-value pairs for non-string keys
          "map_column_3": {
          "$each": [
            [1, "value1"],
            [2, "value2"]
          ]
        },
          # When using $each, use an array of key-value pairs or maps for string keys
          "map_column_4": {
          "$each": [
            {"key1": "value1"},
            ["key2", "value2"]
          ]
        }
      }
    }
  }
}'

Remove matches from a list or set column

Use $pullAll to remove the specified elements from a list or set.

  • Python

  • TypeScript

  • Java

  • curl

from astrapy import DataAPIClient

# Get an existing table
client = DataAPIClient("APPLICATION_TOKEN")
database = client.get_database("API_ENDPOINT")
table = database.get_table("TABLE_NAME")

# Update a row
table.update_one(
    {"title": "Hidden Shadows of the Past", "author": "John Anthony"},
    {
        "$pullAll": {
            "genres": ["SciFi", "Romance"],
        }
    },
)
import { DataAPIClient } from "@datastax/astra-db-ts";

// Get an existing table
const client = new DataAPIClient("APPLICATION_TOKEN");
const database = client.db("API_ENDPOINT");
const table = database.table("TABLE_NAME");

// Update a row
(async function () {
  await table.updateOne(
    {
      title: "Hidden Shadows of the Past",
      author: "John Anthony",
    },
    {
      $pullAll: {
        genres: ["SciFi", "Romance"],
      },
    },
  );
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.core.query.Filter;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.commands.TableUpdateOperation;
import com.datastax.astra.client.tables.definition.rows.Row;
import java.util.Arrays;
import java.util.Map;

public class Example {

  public static void main(String[] args) {
    // Get an existing table
    Table<Row> table =
        new DataAPIClient("APPLICATION_TOKEN")
            .getDatabase("API_ENDPOINT")
            .getTable("TABLE_NAME");

    // Update a row
    Filter filter =
        new Filter(
            Map.of(
                "title", "Hidden Shadows of the Past",
                "author", "John Anthony"));

    TableUpdateOperation update =
        new TableUpdateOperation(
            Map.of("$pullAll", Map.of("genres", Arrays.asList("SciFi", "Romance"))));

    table.updateOne(filter, update);
  }
}
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/TABLE_NAME" \
  --header "Token: APPLICATION_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
  "updateOne": {
    "filter": {
      "title": "Hidden Shadows of the Past",
      "author": "John Anthony"
    },
    "update": {
      "$pullAll": {
        "genres": ["SciFi", "Romance"]
      }
    }
  }
}'

Remove matches from map column

Use $pullAll to remove entries that match the specified keys from a map column.

  • Python

  • TypeScript

  • Java

  • curl

from astrapy import DataAPIClient

# Get an existing table
client = DataAPIClient("APPLICATION_TOKEN")
database = client.get_database("API_ENDPOINT")
table = database.get_table("TABLE_NAME")

# Update a row
table.update_one(
    {"title": "Hidden Shadows of the Past", "author": "John Anthony"},
    {
        "$pullAll": {
            "metadata": ["language", "edition"],
        }
    },
)
import { DataAPIClient } from "@datastax/astra-db-ts";

// Get an existing table
const client = new DataAPIClient("APPLICATION_TOKEN");
const database = client.db("API_ENDPOINT");
const table = database.table("TABLE_NAME");

// Update a row
(async function () {
  await table.updateOne(
    {
      title: "Hidden Shadows of the Past",
      author: "John Anthony",
    },
    {
      $pullAll: {
        metadata: ["language", "edition"],
      },
    },
  );
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.core.query.Filter;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.commands.TableUpdateOperation;
import com.datastax.astra.client.tables.definition.rows.Row;
import java.util.Arrays;
import java.util.Map;

public class Example {

  public static void main(String[] args) {
    // Get an existing table
    Table<Row> table =
        new DataAPIClient("APPLICATION_TOKEN")
            .getDatabase("API_ENDPOINT")
            .getTable("TABLE_NAME");

    // Update a row
    Filter filter =
        new Filter(
            Map.of(
                "title", "Hidden Shadows of the Past",
                "author", "John Anthony"));

    TableUpdateOperation update =
        new TableUpdateOperation(
            Map.of("$pullAll", Map.of("metadata", Arrays.asList("language", "edition"))));

    table.updateOne(filter, update);
  }
}
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/TABLE_NAME" \
  --header "Token: APPLICATION_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
  "updateOne": {
    "filter": {
      "title": "Hidden Shadows of the Past",
      "author": "John Anthony"
    },
    "update": {
      "$pullAll": {
        "metadata": ["language", "edition"]
      }
    }
  }
}'

Unset columns

To unset a column, you can use the $unset operator, or you can use the $set operator and an empty value. Either operation will delete the value in the specified column.

Unsetting a column will produce a tombstone. Excessive tombstones can impact query performance. For more information, see What are tombstones.

  • Python

  • TypeScript

  • Java

  • curl

from astrapy import DataAPIClient

# Get an existing table
client = DataAPIClient("APPLICATION_TOKEN")
database = client.get_database("API_ENDPOINT")
table = database.get_table("TABLE_NAME")

# Update a row
table.update_one({"id": "1013dr3"}, {"$unset": {"genres": ""}})
import { DataAPIClient } from "@datastax/astra-db-ts";

// Get an existing table
const client = new DataAPIClient("APPLICATION_TOKEN");
const database = client.db("API_ENDPOINT");
const table = database.table("TABLE_NAME");

// Update a row
(async function () {
  await table.updateOne(
    {
      id: "1013dr3",
    },
    {
      $unset: {
        genres: "",
      },
    },
  );
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.core.query.Filter;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.commands.TableUpdateOperation;
import com.datastax.astra.client.tables.definition.rows.Row;
import java.util.Map;

public class Example {

  public static void main(String[] args) {
    // Get an existing table
    Table<Row> table =
        new DataAPIClient("APPLICATION_TOKEN")
            .getDatabase("API_ENDPOINT")
            .getTable("TABLE_NAME");

    // Update a row
    Filter filter =
        new Filter(
            Map.of(
                "title", "Hidden Shadows of the Past",
                "author", "John Anthony"));
    TableUpdateOperation update = new TableUpdateOperation().unset("genres");
    table.updateOne(filter, update);
  }
}
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/TABLE_NAME" \
  --header "Token: APPLICATION_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
  "updateOne": {
    "filter": {
      "id": "1013dr3"
    },
    "update": {
        "$unset": {
            "genres": ""
        }
    }
  }
}'

Update a user-defined type column

If a column is a user-defined type, you must update the whole value. You can’t update a partial value. In the example below, president and vice_president both use the same user-defined type, which consists of an email and user_name field.

If the value type of a map, list, or set column is a user-defined type, you can only update the whole value, not a partial value, for each entry. The $push, $each, and $pullAll operators work on map, list, and set columns that have a user-defined type as their value type. For examples, see Update a map column, Append to a list or set column, Append to a map column, Remove matches from a list or set column, and Remove matches from map column.

  • Python

  • TypeScript

  • Java

  • curl

from astrapy import DataAPIClient

# Get an existing table
client = DataAPIClient("APPLICATION_TOKEN")
database = client.get_database("API_ENDPOINT")
table = database.get_table("TABLE_NAME")

# Update a row
table.update_one(
    {"id": "1013dr3"},
    {
        "$set": {
            "president": {"email": "lisa@example.com", "user_name": "lisa_m"},
            "vice_president": {"email": "tanya@example.com", "user_name": "tanya_o"}
        },
    },
)
import { DataAPIClient } from "@datastax/astra-db-ts";

// Get an existing table
const client = new DataAPIClient("APPLICATION_TOKEN");
const database = client.db("API_ENDPOINT");
const table = database.table("TABLE_NAME");

// Update a row
(async function () {
  await table.updateOne(
    {
      id: "1013dr3",
    },
    {
      $set: {
        president: {
          email: "lisa@example.com",
          user_name: "lisa_m",
        },
        "vice_president": {
          email: "tanya@example.com",
          user_name: "tanya_o",
        }
      },
    },
  );
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.core.query.Filter;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.commands.TableUpdateOperation;
import com.datastax.astra.client.tables.definition.rows.Row;
import java.util.Map;

public class Example {
  public static void main(String[] args) {
    // Get an existing table
    Table<Row> table =
        new DataAPIClient("APPLICATION_TOKEN")
            .getDatabase("API_ENDPOINT")
            .getTable("TABLE_NAME");

    // Update a row
    Filter filter = new Filter(Map.of("id", "1013dr3"));
    TableUpdateOperation update =
        new TableUpdateOperation()
            .set("president", Map.of("user_name", "lisa_m", "email", "lisa@example.com"))
            .set("vice_president", Map.of("user_name", "tanya_o", "email", "tanya@example.com"));
    table.updateOne(filter, update);
  }
}
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/TABLE_NAME" \
  --header "Token: APPLICATION_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
  "updateOne": {
    "filter": {
      "id": "1013dr3"
    },
    "update": {
      "$set": {
        "president": {
          "email": "lisa@example.com",
          "user_name": "lisa_m"
        },
        "vice_president": {
          "email": "tanya@example.com",
          "user_name": "tanya_o"
        }
      }
    }
  }
}'

Client reference

  • Python

  • TypeScript

  • Java

  • curl

For more information, see the client reference.

For more information, see the client reference.

For more information, see the client reference.

Client reference documentation is not applicable for HTTP.

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2025 DataStax, an IBM Company | Privacy policy | Terms of use | Manage Privacy Choices

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