Table of Contents

Class UpdateBuilder<T>

Namespace
DataStax.AstraDB.DataApi.Core
Assembly
DataStax.AstraDB.DataApi.dll

Use an UpdateBuilder to specify the changes to make to document(s) in an update operation.

public class UpdateBuilder<T>

Type Parameters

T

The type of the documents in the collection.

Inheritance
UpdateBuilder<T>
Inherited Members

Methods

AddToSet(string, object)

Add a value to a set based on the field name.

public UpdateBuilder<T> AddToSet(string fieldName, object value)

Parameters

fieldName string

The name of the field to add the value to.

value object

The value to add to the set.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Remarks

We recommend using the strongly-typed version AddToSet<TField>(Expression<Func<T, IEnumerable<TField>>>, TField). If the existing field is not a set, it will be converted to a set in the database, which could cause serialization errors.

AddToSetEach(string, IEnumerable<object>)

Add multiple values to a set based on the field name.

public UpdateBuilder<T> AddToSetEach(string fieldName, IEnumerable<object> values)

Parameters

fieldName string

The name of the field to add the values to.

values IEnumerable<object>

The values to add to the set.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Remarks

We recommend using the strongly-typed version AddToSetEach<TField>(Expression<Func<T, IEnumerable<TField>>>, IEnumerable<TField>). If the existing field is not a set, it will be converted to a set in the database, which could cause serialization errors.

AddToSetEach<TField>(Expression<Func<T, IEnumerable<TField>>>, IEnumerable<TField>)

Add multiple values to a set based on the field name.

public UpdateBuilder<T> AddToSetEach<TField>(Expression<Func<T, IEnumerable<TField>>> expression, IEnumerable<TField> values)

Parameters

expression Expression<Func<T, IEnumerable<TField>>>

The expression to use to get the field name.

values IEnumerable<TField>

The values to add to the set.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Type Parameters

TField

The type of the field to add the values to.

Remarks

If the existing field is not a set, it will be converted to a set in the database, which could cause serialization errors.

AddToSet<TField>(Expression<Func<T, IEnumerable<TField>>>, TField)

Add a value to a set based on the field name.

public UpdateBuilder<T> AddToSet<TField>(Expression<Func<T, IEnumerable<TField>>> expression, TField value)

Parameters

expression Expression<Func<T, IEnumerable<TField>>>

The expression to use to get the field name.

value TField

The value to add to the set.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Type Parameters

TField

The type of the field to add the value to.

CurrentDate(string)

Set the value of a field to the current date and time.

public UpdateBuilder<T> CurrentDate(string fieldName)

Parameters

fieldName string

The name of the field to update.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Remarks

We recommend using the strongly-typed version CurrentDate<TField>(Expression<Func<T, TField>>).

CurrentDate<TField>(Expression<Func<T, TField>>)

Set the value of a field to the current date and time.

public UpdateBuilder<T> CurrentDate<TField>(Expression<Func<T, TField>> expression)

Parameters

expression Expression<Func<T, TField>>

The expression to use to get the field name.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Type Parameters

TField

The type of the field to update.

Increment(string, double)

Increment the value of a field by a specified offset.

public UpdateBuilder<T> Increment(string fieldName, double offset)

Parameters

fieldName string

The name of the field to update.

offset double

The amount to increment the field by.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Remarks

We recommend using the strongly-typed version Increment<TField>(Expression<Func<T, TField>>, TField).

Increment<TField>(Expression<Func<T, TField>>, TField)

Increment the value of a field by a specified offset.

public UpdateBuilder<T> Increment<TField>(Expression<Func<T, TField>> expression, TField offset)

Parameters

expression Expression<Func<T, TField>>

The expression to use to get the field name.

offset TField

The amount to increment the field by.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Type Parameters

TField

The type of the field to update.

Max(string, double)

Set the value of a field to whichever is higher, the current value or the specified value.

public UpdateBuilder<T> Max(string fieldName, double value)

Parameters

fieldName string

The name of the field to update.

value double

The potential new value

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Remarks

We recommend using the strongly-typed version Max<TField>(Expression<Func<T, TField>>, TField).

Max<TField>(Expression<Func<T, TField>>, TField)

Set the value of a field to whichever is higher, the current value or the specified value.

public UpdateBuilder<T> Max<TField>(Expression<Func<T, TField>> expression, TField value)

Parameters

expression Expression<Func<T, TField>>

The expression to use to get the field name.

value TField

The potential new value.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Type Parameters

TField

The type of the field to update.

Min(string, double)

Set the value of a field to whichever is lower, the current value or the specified value.

public UpdateBuilder<T> Min(string fieldName, double value)

Parameters

fieldName string

The name of the field to update.

value double

The potential new value.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Remarks

We recommend using the strongly-typed version Min<TField>(Expression<Func<T, TField>>, TField).

Min<TField>(Expression<Func<T, TField>>, TField)

Set the value of a field to whichever is lower, the current value or the specified value.

public UpdateBuilder<T> Min<TField>(Expression<Func<T, TField>> expression, TField value)

Parameters

expression Expression<Func<T, TField>>

The expression to use to get the field name.

value TField

The potential new value.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Type Parameters

TField

The type of the field to update.

Multiply(string, double)

Set the value of a field to the product of the current value and the specified value.

public UpdateBuilder<T> Multiply(string fieldName, double value)

Parameters

fieldName string

The name of the field to update.

value double

The value to multiply the field by.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Remarks

We recommend using the strongly-typed version Multiply<TField>(Expression<Func<T, TField>>, TField).

Multiply<TField>(Expression<Func<T, TField>>, TField)

Set the value of a field to the product of the current value and the specified value.

public UpdateBuilder<T> Multiply<TField>(Expression<Func<T, TField>> expression, TField value)

Parameters

expression Expression<Func<T, TField>>

The expression to use to get the field name.

value TField

The value to multiply the field by.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Type Parameters

TField

The type of the field to update.

PopFirst(string)

Remove the first element from a set based on the field name.

public UpdateBuilder<T> PopFirst(string fieldName)

Parameters

fieldName string

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Remarks

We recommend using the strongly-typed version PopFirst<TField>(Expression<Func<T, TField>>).

PopFirst<TField>(Expression<Func<T, TField>>)

Remove the first element from a set based on the field name.

public UpdateBuilder<T> PopFirst<TField>(Expression<Func<T, TField>> expression)

Parameters

expression Expression<Func<T, TField>>

The expression to use to get the field name.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Type Parameters

TField

The type of the field to remove the first element from.

PopLast(string)

Remove the last element from a set based on the field name.

public UpdateBuilder<T> PopLast(string fieldName)

Parameters

fieldName string

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Remarks

We recommend using the strongly-typed version PopLast<TField>(Expression<Func<T, TField>>).

PopLast<TField>(Expression<Func<T, TField>>)

Remove the last element from a set based on the field name.

public UpdateBuilder<T> PopLast<TField>(Expression<Func<T, TField>> expression)

Parameters

expression Expression<Func<T, TField>>

The expression to use to get the field name.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Type Parameters

TField

The type of the field to remove the last element from.

PullAll<TField>(Expression<Func<T, IEnumerable<TField>>>, IEnumerable<TField>)

Remove all instances matching the specified values (list/set).

public UpdateBuilder<T> PullAll<TField>(Expression<Func<T, IEnumerable<TField>>> expression, IEnumerable<TField> values)

Parameters

expression Expression<Func<T, IEnumerable<TField>>>
values IEnumerable<TField>

Returns

UpdateBuilder<T>

Type Parameters

TField

PullAll<TField>(string, IEnumerable<TField>)

Remove all instances matching the specified values (list/set) or keys (dictionary/map).

public UpdateBuilder<T> PullAll<TField>(string fieldName, IEnumerable<TField> values)

Parameters

fieldName string
values IEnumerable<TField>

Returns

UpdateBuilder<T>

Type Parameters

TField

PullAll<TKey, TVal>(Expression<Func<T, IDictionary<TKey, TVal>>>, IEnumerable<TKey>)

Remove all instances matching the specified keys (dictionary/map).

public UpdateBuilder<T> PullAll<TKey, TVal>(Expression<Func<T, IDictionary<TKey, TVal>>> expression, IEnumerable<TKey> keys)

Parameters

expression Expression<Func<T, IDictionary<TKey, TVal>>>
keys IEnumerable<TKey>

Returns

UpdateBuilder<T>

Type Parameters

TKey
TVal

Push(string, object, int?)

Add a value to a set at a specified position.

public UpdateBuilder<T> Push(string fieldName, object value, int? position = null)

Parameters

fieldName string

The name of the field to add the value to.

value object

The value to add to the set.

position int?

The position to add the value to. If null, the value will be added to the end of the set.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Remarks

We recommend using the strongly-typed version Push<TField>(Expression<Func<T, IEnumerable<TField>>>, TField, int?).

PushEach(string, IEnumerable<object>, int?)

Add multiple values to a set starting at a specified position.

public UpdateBuilder<T> PushEach(string fieldName, IEnumerable<object> values, int? position = null)

Parameters

fieldName string

The name of the field to add the values to.

values IEnumerable<object>

The values to add to the set.

position int?

The position to add the values to. If null, the values will be added to the end of the set.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Remarks

PushEach<TField>(Expression<Func<T, IEnumerable<TField>>>, IEnumerable<TField>, int?)

Add multiple values to a set starting at a specified position.

public UpdateBuilder<T> PushEach<TField>(Expression<Func<T, IEnumerable<TField>>> expression, IEnumerable<TField> values, int? position = null)

Parameters

expression Expression<Func<T, IEnumerable<TField>>>

The expression to use to get the field name.

values IEnumerable<TField>

The values to add to the set.

position int?

The position to add the values to. If null, the values will be added to the end of the set.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Type Parameters

TField

The type of the field to add the values to.

PushEach<TKey, TVal>(Expression<Func<T, IDictionary<TKey, TVal>>>, IDictionary<TKey, TVal>)

Add multiple key-value pairs to a map.

public UpdateBuilder<T> PushEach<TKey, TVal>(Expression<Func<T, IDictionary<TKey, TVal>>> expression, IDictionary<TKey, TVal> value)

Parameters

expression Expression<Func<T, IDictionary<TKey, TVal>>>

The expression to use to get the field name.

value IDictionary<TKey, TVal>

The key-value pairs to add to the map as a dictionary.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Type Parameters

TKey

The type of the map keys

TVal

The type of the map values

PushEach<TKey, TVal>(Expression<Func<T, IDictionary<TKey, TVal>>>, (TKey, TVal)[])

Add multiple key-value pairs to a map.

public UpdateBuilder<T> PushEach<TKey, TVal>(Expression<Func<T, IDictionary<TKey, TVal>>> expression, (TKey, TVal)[] pairs)

Parameters

expression Expression<Func<T, IDictionary<TKey, TVal>>>

The expression to use to get the field name.

pairs (TKey, TVal)[]

The key-value pairs to add to the map as 2-item tuples.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Type Parameters

TKey

The type of the map keys

TVal

The type of the map values

PushEach<TKey, TVal>(string, IDictionary<TKey, TVal>)

Add multiple key-value pairs to a map.

public UpdateBuilder<T> PushEach<TKey, TVal>(string fieldName, IDictionary<TKey, TVal> value)

Parameters

fieldName string

The name of the field to add the pairs to.

value IDictionary<TKey, TVal>

The key-value pairs to add to the map as a dictionary.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Type Parameters

TKey

The type of the map keys

TVal

The type of the map values

Remarks

PushEach<TKey, TVal>(string, (TKey, TVal)[])

Add multiple key-value pairs to a map.

public UpdateBuilder<T> PushEach<TKey, TVal>(string fieldName, (TKey, TVal)[] pairs)

Parameters

fieldName string

The name of the field to add the pairs to.

pairs (TKey, TVal)[]

The key-value pairs to add to the map as 2-item tuples.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Type Parameters

TKey

The type of the map keys

TVal

The type of the map values

Remarks

Push<TField>(Expression<Func<T, IEnumerable<TField>>>, TField, int?)

Add a value to a set at a specified position.

public UpdateBuilder<T> Push<TField>(Expression<Func<T, IEnumerable<TField>>> expression, TField value, int? position = null)

Parameters

expression Expression<Func<T, IEnumerable<TField>>>

The expression to use to get the field name.

value TField

The value to add to the set.

position int?

The position to add the value to. If null, the value will be added to the end of the set.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Type Parameters

TField

The type of the field to add the value to.

Push<TKey, TVal>(Expression<Func<T, IDictionary<TKey, TVal>>>, IDictionary<TKey, TVal>)

Add a key-value pair to a map.

public UpdateBuilder<T> Push<TKey, TVal>(Expression<Func<T, IDictionary<TKey, TVal>>> expression, IDictionary<TKey, TVal> value)

Parameters

expression Expression<Func<T, IDictionary<TKey, TVal>>>

The expression to use to get the field name.

value IDictionary<TKey, TVal>

The key-value pair to add to the map as a single-entry dictionary.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Type Parameters

TKey

The type of the map keys

TVal

The type of the map values

Push<TKey, TVal>(Expression<Func<T, IDictionary<TKey, TVal>>>, (TKey, TVal))

Add a key-value pair to a map.

public UpdateBuilder<T> Push<TKey, TVal>(Expression<Func<T, IDictionary<TKey, TVal>>> expression, (TKey, TVal) pair)

Parameters

expression Expression<Func<T, IDictionary<TKey, TVal>>>

The expression to use to get the field name.

pair (TKey, TVal)

The key-value pair to add to the map as a 2-item tuple.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Type Parameters

TKey

The type of the map keys

TVal

The type of the map values

Push<TKey, TVal>(string, IDictionary<TKey, TVal>)

Add a key-value pair to a map.

public UpdateBuilder<T> Push<TKey, TVal>(string fieldName, IDictionary<TKey, TVal> value)

Parameters

fieldName string

The name of the field to add the pair to.

value IDictionary<TKey, TVal>

The key-value pair to add to the map as a single-entry dictionary.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Type Parameters

TKey

The type of the map keys

TVal

The type of the map values

Remarks

Push<TKey, TVal>(string, (TKey, TVal))

Add a key-value pair to a map.

public UpdateBuilder<T> Push<TKey, TVal>(string fieldName, (TKey, TVal) pair)

Parameters

fieldName string

The name of the field to add the pair to.

pair (TKey, TVal)

The key-value pair to add to the map as a 2-item tuple.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Type Parameters

TKey

The type of the map keys

TVal

The type of the map values

Remarks

Rename(string, string)

Rename a field in the document.

public UpdateBuilder<T> Rename(string fieldName, string newFieldName)

Parameters

fieldName string

The name of the field to rename.

newFieldName string

The new name for the field.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Remarks

We recommend using the strongly-typed version Rename<TField>(Expression<Func<T, TField>>, Expression<Func<T, TField>>).

Rename<TField>(Expression<Func<T, TField>>, Expression<Func<T, TField>>)

Rename a field in the document.

public UpdateBuilder<T> Rename<TField>(Expression<Func<T, TField>> expression, Expression<Func<T, TField>> newExpression)

Parameters

expression Expression<Func<T, TField>>

The expression to use to get the field name.

newExpression Expression<Func<T, TField>>

The expression to use to get the new field name.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Type Parameters

TField

The type of the field to rename.

Set(string, object)

Set the value of a field to a specified value.

public UpdateBuilder<T> Set(string fieldName, object value)

Parameters

fieldName string

The name of the field to set.

value object

The value to set.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Remarks

We recommend using the strongly-typed version Set<TField>(Expression<Func<T, TField>>, TField).

SetOnInsert(string, object)

Set the value of a field to a specified value only when inserting a new document.

public UpdateBuilder<T> SetOnInsert(string fieldName, object value)

Parameters

fieldName string

The name of the field to set.

value object

The value to set.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Remarks

We recommend using the strongly-typed version SetOnInsert<TField>(Expression<Func<T, TField>>, TField).

SetOnInsert<TField>(Expression<Func<T, TField>>, TField)

Set the value of a field to a specified value only when inserting a new document.

public UpdateBuilder<T> SetOnInsert<TField>(Expression<Func<T, TField>> expression, TField value)

Parameters

expression Expression<Func<T, TField>>

The expression to use to get the field name.

value TField

The value to set.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Type Parameters

TField

The type of the field to set.

Set<TField>(Expression<Func<T, TField>>, TField)

Set the value of a field to a specified value.

public UpdateBuilder<T> Set<TField>(Expression<Func<T, TField>> expression, TField value)

Parameters

expression Expression<Func<T, TField>>

The expression to use to get the field name.

value TField

The value to set.

Returns

UpdateBuilder<T>

The UpdateBuilder instance

Type Parameters

TField

The type of the field to set.

Set<TKey, TValue>(Expression<Func<T, IDictionary<TKey, TValue>>>, (TKey, TValue)[])

Set the value of a dictionary field to a specified value.

public UpdateBuilder<T> Set<TKey, TValue>(Expression<Func<T, IDictionary<TKey, TValue>>> expression, (TKey, TValue)[] pairs)

Parameters

expression Expression<Func<T, IDictionary<TKey, TValue>>>

An expression that represents the target dictionary field

pairs (TKey, TValue)[]

The value to set, as array of key-value pairs (tuples).

Returns

UpdateBuilder<T>

The UpdateBuilder instance

Type Parameters

TKey

The type of the dictionary keys

TValue

The type of the dictionary values

Set<TKey, TValue>(string, (TKey, TValue)[])

Set the value of a dictionary field to a specified value.

public UpdateBuilder<T> Set<TKey, TValue>(string fieldName, (TKey, TValue)[] pairs)

Parameters

fieldName string

The name of the field to set.

pairs (TKey, TValue)[]

The value to set, as array of key-value pairs (tuples).

Returns

UpdateBuilder<T>

The UpdateBuilder instance

Type Parameters

TKey

The type of the dictionary keys

TValue

The type of the dictionary values

Remarks

We recommend using the strongly-typed version Set<TField>(Expression<Func<T, TField>>, TField).

Unset(string)

Remove the current value from a field.

public UpdateBuilder<T> Unset(string fieldName)

Parameters

fieldName string

The name of the field to unset.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Remarks

We recommend using the strongly-typed version Unset<TField>(Expression<Func<T, TField>>).

Unset<TField>(Expression<Func<T, TField>>)

Remove the current value from a field.

public UpdateBuilder<T> Unset<TField>(Expression<Func<T, TField>> expression)

Parameters

expression Expression<Func<T, TField>>

The expression to use to get the field name.

Returns

UpdateBuilder<T>

The UpdateBuilder instance.

Type Parameters

TField

The type of the field to unset.