Update operators for tables
Some Data API commands, like Update a row, use update operators to modify rows in a table.
Set
The $set
operator sets the value of the specified column to the specified value.
To update a value to a map that 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.
Example setting a non-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"},
{
"$set": {"rating": 4.5, "genres": ["Fiction", "Drama"]},
},
)
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"],
},
},
);
})();
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"));
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"]
}
}
}
}'
Example setting a map column:
-
Python
-
TypeScript
-
Java
-
curl
If the updated map includes non-string keys, you must use an array of key-value pairs to update the map column.
With the Python client, you can also use DataAPIMap
to encode maps that use non-string keys.
Otherwise, you can use an array of key-value pairs or a normal map.
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"},
}
},
)
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.
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",
},
},
},
);
})();
The Java client supports updates of a row with a map column that includes non-string keys. (You don’t need to use an array of key-value pairs to represent the map column.)
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.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,
// but the insertion can still be represented as a map
// instead of an array of key-value pairs
Map<Integer, String> mapColumn1 = Map.of(1, "value1", 2, "value2");
// This map does not have non-string keys
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);
}
}
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.
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"
}
}
}
}
}'
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 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": ""
}
}
}
}'
Push
The $push
operator appends a single element to a map, list, or set.
To append multiple items, use the $each
operator with $push
.
When appending to a map, 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.
Example appending to a list or set 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"},
{
"$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"]
}
}
}
}
}'
Example appending to a map column:
-
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"]
]
}
}
}
}
}'
Each
The $each
operator modifies the $push
operator to append multiple items to a map, list, or set.
Example appending to a list or set 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"},
{
"$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"]
}
}
}
}
}'
Example appending to a map column:
-
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"]
]
}
}
}
}
}'
Pull all
The $pullAll
operator removes the specified elements from a list or set, or removes entries that match the specified keys from a map.
Example removing matches from a list or set 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": {
"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"]
}
}
}
}'
Example removing 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(
{"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"]
}
}
}
}'
Combine operators
You can use multiple update operators in a single update.
-
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": ""
}
}
}
}'
Unsupported operators
-
$rename
isn’t supported. Instead, usealterTable
to add and drop columns. -
$currentDate
isn’t supported. -
The array operators
$addToSet
,$pop
, and$position
aren’t supported.