Update operators for tables (TypeScript)

Some Data API commands, like Update a row (TypeScript), use update operators to modify rows in a table.

Set

The $set operator sets the value of the specified column to the specified value.

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");

// 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

The $unset operator sets the specified column’s value to null or the equivalent empty form, such as [] or {} for map, list, and set types.

Unsetting a column produces a tombstone. Excessive tombstones can impact query performance.

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");

// Update a row
(async function () {
  await table.updateOne(
    {
      title: "Hidden Shadows of the Past",
      author: "John Anthony",
    },
    {
      $unset: {
        genres: "",
      },
    },
  );
})();

Combine operators

You can use multiple update operators in a single update.

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");

// 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: "",
      },
    },
  );
})();

Unsupported operators

  • $rename isn’t supported. Instead, use alterTable to add and drop columns.

  • $currentDate isn’t supported.

  • The array operators $push, $each, $pullAll, $addToSet, $pop, and $position aren’t supported.

Was this helpful?

Give Feedback

How can we improve the documentation?

© Copyright IBM Corporation 2026 | 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: Contact IBM