Update operators for tables (Go)

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

Set

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

package main

import (
	"context"
	"log"

	"github.com/datastax/astra-db-go/v2/astra"
	"github.com/datastax/astra-db-go/v2/astra/filter"
	"github.com/datastax/astra-db-go/v2/astra/options"
	"github.com/datastax/astra-db-go/v2/astra/update"
)

func main() {
	ctx := context.Background()
	// Get an existing table
	client := astra.NewClient(
		options.API().SetEnvironment(options.EnvironmentHCD),
	)

	database := client.Database(
		"API_ENDPOINT",
		options.API().
			SetUsernamePasswordTokenProvider(
				"USERNAME",
				"PASSWORD",
			).
			SetKeyspace("KEYSPACE_NAME"),
	)

	table := database.Table("TABLE_NAME")

	// Update a row
	err := table.UpdateOne(
		ctx,
		filter.And(
			filter.Eq("title", "Hidden Shadows of the Past"),
			filter.Eq("author", "John Anthony"),
		),
		update.Table().
			Set("rating", 4.5).
			Set("genres", []string{"Fiction", "Drama"}),
	)
	if err != nil {
		log.Fatal(err)
	}
}

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.

package main

import (
	"context"
	"log"

	"github.com/datastax/astra-db-go/v2/astra"
	"github.com/datastax/astra-db-go/v2/astra/filter"
	"github.com/datastax/astra-db-go/v2/astra/options"
	"github.com/datastax/astra-db-go/v2/astra/update"
)

func main() {
	ctx := context.Background()
	// Get an existing table
	client := astra.NewClient(
		options.API().SetEnvironment(options.EnvironmentHCD),
	)

	database := client.Database(
		"API_ENDPOINT",
		options.API().
			SetUsernamePasswordTokenProvider(
				"USERNAME",
				"PASSWORD",
			).
			SetKeyspace("KEYSPACE_NAME"),
	)

	table := database.Table("TABLE_NAME")

	// Update a row
	err := table.UpdateOne(
		ctx,
		filter.And(
			filter.Eq("title", "Hidden Shadows of the Past"),
			filter.Eq("author", "John Anthony"),
		),
		update.Table().Unset("genres"),
	)
	if err != nil {
		log.Fatal(err)
	}
}

Combine operators

You can use multiple update operators in a single update.

package main

import (
	"context"
	"log"

	"github.com/datastax/astra-db-go/v2/astra"
	"github.com/datastax/astra-db-go/v2/astra/filter"
	"github.com/datastax/astra-db-go/v2/astra/options"
	"github.com/datastax/astra-db-go/v2/astra/update"
)

func main() {
	ctx := context.Background()
	// Get an existing table
	client := astra.NewClient(
		options.API().SetEnvironment(options.EnvironmentHCD),
	)

	database := client.Database(
		"API_ENDPOINT",
		options.API().
			SetUsernamePasswordTokenProvider(
				"USERNAME",
				"PASSWORD",
			).
			SetKeyspace("KEYSPACE_NAME"),
	)

	table := database.Table("TABLE_NAME")

	// Update a row
	err := table.UpdateOne(
		ctx,
		filter.And(
			filter.Eq("title", "Hidden Shadows of the Past"),
			filter.Eq("author", "John Anthony"),
		),
		update.Table().
			Set("rating", 4.5).
			Set("genres", []string{"Fiction", "Drama"}).
			Unset("borrower"),
	)
	if err != nil {
		log.Fatal(err)
	}
}

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