Class UpdateBuilder<T>
Use an UpdateBuilder to specify the changes to make to document(s) in an update operation.
public class UpdateBuilder<T>
Type Parameters
TThe 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
fieldNamestringThe name of the field to add the value to.
valueobjectThe 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
fieldNamestringThe name of the field to add the values to.
valuesIEnumerable<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
expressionExpression<Func<T, IEnumerable<TField>>>The expression to use to get the field name.
valuesIEnumerable<TField>The values to add to the set.
Returns
- UpdateBuilder<T>
The UpdateBuilder instance.
Type Parameters
TFieldThe 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
expressionExpression<Func<T, IEnumerable<TField>>>The expression to use to get the field name.
valueTFieldThe value to add to the set.
Returns
- UpdateBuilder<T>
The UpdateBuilder instance.
Type Parameters
TFieldThe 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
fieldNamestringThe 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
expressionExpression<Func<T, TField>>The expression to use to get the field name.
Returns
- UpdateBuilder<T>
The UpdateBuilder instance.
Type Parameters
TFieldThe 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
fieldNamestringThe name of the field to update.
offsetdoubleThe 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
expressionExpression<Func<T, TField>>The expression to use to get the field name.
offsetTFieldThe amount to increment the field by.
Returns
- UpdateBuilder<T>
The UpdateBuilder instance.
Type Parameters
TFieldThe 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
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
expressionExpression<Func<T, TField>>The expression to use to get the field name.
valueTFieldThe potential new value.
Returns
- UpdateBuilder<T>
The UpdateBuilder instance.
Type Parameters
TFieldThe 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
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
expressionExpression<Func<T, TField>>The expression to use to get the field name.
valueTFieldThe potential new value.
Returns
- UpdateBuilder<T>
The UpdateBuilder instance.
Type Parameters
TFieldThe 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
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
expressionExpression<Func<T, TField>>The expression to use to get the field name.
valueTFieldThe value to multiply the field by.
Returns
- UpdateBuilder<T>
The UpdateBuilder instance.
Type Parameters
TFieldThe 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
fieldNamestring
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
expressionExpression<Func<T, TField>>The expression to use to get the field name.
Returns
- UpdateBuilder<T>
The UpdateBuilder instance.
Type Parameters
TFieldThe 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
fieldNamestring
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
expressionExpression<Func<T, TField>>The expression to use to get the field name.
Returns
- UpdateBuilder<T>
The UpdateBuilder instance.
Type Parameters
TFieldThe 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
expressionExpression<Func<T, IEnumerable<TField>>>valuesIEnumerable<TField>
Returns
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
fieldNamestringvaluesIEnumerable<TField>
Returns
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
expressionExpression<Func<T, IDictionary<TKey, TVal>>>keysIEnumerable<TKey>
Returns
Type Parameters
TKeyTVal
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
fieldNamestringThe name of the field to add the value to.
valueobjectThe value to add to the set.
positionint?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
fieldNamestringThe name of the field to add the values to.
valuesIEnumerable<object>The values to add to the set.
positionint?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
We recommend using the strongly-typed version PushEach<TField>(Expression<Func<T, IEnumerable<TField>>>, IEnumerable<TField>, int?).
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
expressionExpression<Func<T, IEnumerable<TField>>>The expression to use to get the field name.
valuesIEnumerable<TField>The values to add to the set.
positionint?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
TFieldThe 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
expressionExpression<Func<T, IDictionary<TKey, TVal>>>The expression to use to get the field name.
valueIDictionary<TKey, TVal>The key-value pairs to add to the map as a dictionary.
Returns
- UpdateBuilder<T>
The UpdateBuilder instance.
Type Parameters
TKeyThe type of the map keys
TValThe 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
expressionExpression<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
TKeyThe type of the map keys
TValThe 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
fieldNamestringThe name of the field to add the pairs to.
valueIDictionary<TKey, TVal>The key-value pairs to add to the map as a dictionary.
Returns
- UpdateBuilder<T>
The UpdateBuilder instance.
Type Parameters
TKeyThe type of the map keys
TValThe type of the map values
Remarks
We recommend using the strongly-typed version PushEach<TKey, TVal>(Expression<Func<T, IDictionary<TKey, TVal>>>, IDictionary<TKey, TVal>).
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
fieldNamestringThe 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
TKeyThe type of the map keys
TValThe type of the map values
Remarks
We recommend using the strongly-typed version PushEach<TKey, TVal>(Expression<Func<T, IDictionary<TKey, TVal>>>, (TKey, TVal)[]).
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
expressionExpression<Func<T, IEnumerable<TField>>>The expression to use to get the field name.
valueTFieldThe value to add to the set.
positionint?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
TFieldThe 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
expressionExpression<Func<T, IDictionary<TKey, TVal>>>The expression to use to get the field name.
valueIDictionary<TKey, TVal>The key-value pair to add to the map as a single-entry dictionary.
Returns
- UpdateBuilder<T>
The UpdateBuilder instance.
Type Parameters
TKeyThe type of the map keys
TValThe 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
expressionExpression<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
TKeyThe type of the map keys
TValThe 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
fieldNamestringThe name of the field to add the pair to.
valueIDictionary<TKey, TVal>The key-value pair to add to the map as a single-entry dictionary.
Returns
- UpdateBuilder<T>
The UpdateBuilder instance.
Type Parameters
TKeyThe type of the map keys
TValThe type of the map values
Remarks
We recommend using the strongly-typed version Push<TKey, TVal>(Expression<Func<T, IDictionary<TKey, TVal>>>, IDictionary<TKey, TVal>).
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
fieldNamestringThe 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
TKeyThe type of the map keys
TValThe type of the map values
Remarks
We recommend using the strongly-typed version Push<TKey, TVal>(Expression<Func<T, IDictionary<TKey, TVal>>>, (TKey, TVal)).
Rename(string, string)
Rename a field in the document.
public UpdateBuilder<T> Rename(string fieldName, string newFieldName)
Parameters
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
expressionExpression<Func<T, TField>>The expression to use to get the field name.
newExpressionExpression<Func<T, TField>>The expression to use to get the new field name.
Returns
- UpdateBuilder<T>
The UpdateBuilder instance.
Type Parameters
TFieldThe 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
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
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
expressionExpression<Func<T, TField>>The expression to use to get the field name.
valueTFieldThe value to set.
Returns
- UpdateBuilder<T>
The UpdateBuilder instance.
Type Parameters
TFieldThe 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
expressionExpression<Func<T, TField>>The expression to use to get the field name.
valueTFieldThe value to set.
Returns
- UpdateBuilder<T>
The UpdateBuilder instance
Type Parameters
TFieldThe 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
expressionExpression<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
TKeyThe type of the dictionary keys
TValueThe 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
fieldNamestringThe 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
TKeyThe type of the dictionary keys
TValueThe 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
fieldNamestringThe 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
expressionExpression<Func<T, TField>>The expression to use to get the field name.
Returns
- UpdateBuilder<T>
The UpdateBuilder instance.
Type Parameters
TFieldThe type of the field to unset.