Table of Contents

Class Update<TDocument>

Namespace
MongoDB.Driver.Builders
Assembly
MongoDB.Driver.Legacy.dll

A builder for creating update modifiers.

public static class Update<TDocument>

Type Parameters

TDocument

The document type.

Inheritance
Update<TDocument>
Inherited Members

Methods

AddToSetEach<TValue>(Expression<Func<TDocument, IEnumerable<TValue>>>, IEnumerable<TValue>)

Adds a list of values to a named array element adding each value only if it not already in the array (see $addToSet and $each).

public static UpdateBuilder<TDocument> AddToSetEach<TValue>(Expression<Func<TDocument, IEnumerable<TValue>>> memberExpression, IEnumerable<TValue> values)

Parameters

memberExpression Expression<Func<TDocument, IEnumerable<TValue>>>

The member expression.

values IEnumerable<TValue>

The values to add to the set.

Returns

UpdateBuilder<TDocument>

The builder (so method calls can be chained).

Type Parameters

TValue

The type of the enumerable member values.

AddToSet<TValue>(Expression<Func<TDocument, IEnumerable<TValue>>>, TValue)

Adds a value to a named array element if the value is not already in the array (see $addToSet).

public static UpdateBuilder<TDocument> AddToSet<TValue>(Expression<Func<TDocument, IEnumerable<TValue>>> memberExpression, TValue value)

Parameters

memberExpression Expression<Func<TDocument, IEnumerable<TValue>>>

The member expression.

value TValue

The value to add to the set.

Returns

UpdateBuilder<TDocument>

The builder (so method calls can be chained).

Type Parameters

TValue

The type of the enumerable member values.

BitwiseAnd(Expression<Func<TDocument, int>>, int)

Sets the named element to the bitwise and of its value with another value (see $bit with "and").

public static UpdateBuilder<TDocument> BitwiseAnd(Expression<Func<TDocument, int>> memberExpression, int value)

Parameters

memberExpression Expression<Func<TDocument, int>>

The member expression.

value int

The value to be and-ed with the current value.

Returns

UpdateBuilder<TDocument>

The builder (so method calls can be chained).

BitwiseAnd(Expression<Func<TDocument, long>>, long)

Sets the named element to the bitwise and of its value with another value (see $bit with "and").

public static UpdateBuilder<TDocument> BitwiseAnd(Expression<Func<TDocument, long>> memberExpression, long value)

Parameters

memberExpression Expression<Func<TDocument, long>>

The member expression.

value long

The value to be and-ed with the current value.

Returns

UpdateBuilder<TDocument>

The builder (so method calls can be chained).

BitwiseOr(Expression<Func<TDocument, int>>, int)

Sets the named element to the bitwise or of its value with another value (see $bit with "or").

public static UpdateBuilder<TDocument> BitwiseOr(Expression<Func<TDocument, int>> memberExpression, int value)

Parameters

memberExpression Expression<Func<TDocument, int>>

The member expression.

value int

The value to be or-ed with the current value.

Returns

UpdateBuilder<TDocument>

The builder (so method calls can be chained).

BitwiseOr(Expression<Func<TDocument, long>>, long)

Sets the named element to the bitwise or of its value with another value (see $bit with "or").

public static UpdateBuilder<TDocument> BitwiseOr(Expression<Func<TDocument, long>> memberExpression, long value)

Parameters

memberExpression Expression<Func<TDocument, long>>

The member expression.

value long

The value to be or-ed with the current value.

Returns

UpdateBuilder<TDocument>

The builder (so method calls can be chained).

BitwiseXor(Expression<Func<TDocument, int>>, int)

Sets the named element to the bitwise xor of its value with another value (see $bit with "xor").

public static UpdateBuilder<TDocument> BitwiseXor(Expression<Func<TDocument, int>> memberExpression, int value)

Parameters

memberExpression Expression<Func<TDocument, int>>

The member expression.

value int

The value to be xor-ed with the current value.

Returns

UpdateBuilder<TDocument>

The builder (so method calls can be chained).

BitwiseXor(Expression<Func<TDocument, long>>, long)

Sets the named element to the bitwise xor of its value with another value (see $bit with "xor").

public static UpdateBuilder<TDocument> BitwiseXor(Expression<Func<TDocument, long>> memberExpression, long value)

Parameters

memberExpression Expression<Func<TDocument, long>>

The member expression.

value long

The value to be xor-ed with the current value.

Returns

UpdateBuilder<TDocument>

The builder (so method calls can be chained).

Combine(params IMongoUpdate[])

Combines several UpdateBuilders into a single UpdateBuilder.

public static UpdateBuilder<TDocument> Combine(params IMongoUpdate[] updates)

Parameters

updates IMongoUpdate[]

The updates to combine.

Returns

UpdateBuilder<TDocument>

A combined UpdateBuilder.

Combine(IEnumerable<IMongoUpdate>)

Combines several UpdateBuilders into a single UpdateBuilder.

public static UpdateBuilder<TDocument> Combine(IEnumerable<IMongoUpdate> updates)

Parameters

updates IEnumerable<IMongoUpdate>

The UpdateBuilders to combine.

Returns

UpdateBuilder<TDocument>

A combined UpdateBuilder.

CurrentDate(Expression<Func<TDocument, BsonDateTime>>)

Sets the value of the named element to the current date (see $currentDate).

public static UpdateBuilder<TDocument> CurrentDate(Expression<Func<TDocument, BsonDateTime>> memberExpression)

Parameters

memberExpression Expression<Func<TDocument, BsonDateTime>>

The member expression.

Returns

UpdateBuilder<TDocument>

The builder (so method calls can be chained).

CurrentDate(Expression<Func<TDocument, BsonTimestamp>>)

Sets the value of the named element to the current date (see $currentDate).

public static UpdateBuilder<TDocument> CurrentDate(Expression<Func<TDocument, BsonTimestamp>> memberExpression)

Parameters

memberExpression Expression<Func<TDocument, BsonTimestamp>>

The member expression.

Returns

UpdateBuilder<TDocument>

The builder (so method calls can be chained).

CurrentDate(Expression<Func<TDocument, DateTime>>)

Sets the value of the named element to the current date (see $currentDate).

public static UpdateBuilder<TDocument> CurrentDate(Expression<Func<TDocument, DateTime>> memberExpression)

Parameters

memberExpression Expression<Func<TDocument, DateTime>>

The member expression.

Returns

UpdateBuilder<TDocument>

The builder (so method calls can be chained).

Inc(Expression<Func<TDocument, double>>, double)

Increments the named element by a value (see $inc).

public static UpdateBuilder<TDocument> Inc(Expression<Func<TDocument, double>> memberExpression, double value)

Parameters

memberExpression Expression<Func<TDocument, double>>

The member expression.

value double

The value to increment by.

Returns

UpdateBuilder<TDocument>

The builder (so method calls can be chained).

Inc(Expression<Func<TDocument, int>>, int)

Increments the named element by a value (see $inc).

public static UpdateBuilder<TDocument> Inc(Expression<Func<TDocument, int>> memberExpression, int value)

Parameters

memberExpression Expression<Func<TDocument, int>>

The member expression.

value int

The value to increment by.

Returns

UpdateBuilder<TDocument>

The builder (so method calls can be chained).

Inc(Expression<Func<TDocument, long>>, long)

Increments the named element by a value (see $inc).

public static UpdateBuilder<TDocument> Inc(Expression<Func<TDocument, long>> memberExpression, long value)

Parameters

memberExpression Expression<Func<TDocument, long>>

The member expression.

value long

The value to increment by.

Returns

UpdateBuilder<TDocument>

The builder (so method calls can be chained).

Max<TMember>(Expression<Func<TDocument, TMember>>, TMember)

Updates the named element if and only if the provided value is greater than its current value (see $max).

public static UpdateBuilder<TDocument> Max<TMember>(Expression<Func<TDocument, TMember>> memberExpression, TMember value)

Parameters

memberExpression Expression<Func<TDocument, TMember>>

The member expression.

value TMember

The value to use.

Returns

UpdateBuilder<TDocument>

The builder (so method calls can be chained).

Type Parameters

TMember

The type of the member.

Min<TMember>(Expression<Func<TDocument, TMember>>, TMember)

Updates the named element if and only if the provided value is less than its current value (see $max).

public static UpdateBuilder<TDocument> Min<TMember>(Expression<Func<TDocument, TMember>> memberExpression, TMember value)

Parameters

memberExpression Expression<Func<TDocument, TMember>>

The member expression.

value TMember

The value to use.

Returns

UpdateBuilder<TDocument>

The builder (so method calls can be chained).

Type Parameters

TMember

The type of the member.

Mul(Expression<Func<TDocument, double>>, double)

Multiplies the named element by a value (see $mul).

public static UpdateBuilder<TDocument> Mul(Expression<Func<TDocument, double>> memberExpression, double value)

Parameters

memberExpression Expression<Func<TDocument, double>>

The member expression.

value double

The value to multiply by.

Returns

UpdateBuilder<TDocument>

The builder (so method calls can be chained).

Mul(Expression<Func<TDocument, int>>, int)

Multiplies the named element by a value (see $mul).

public static UpdateBuilder<TDocument> Mul(Expression<Func<TDocument, int>> memberExpression, int value)

Parameters

memberExpression Expression<Func<TDocument, int>>

The member expression.

value int

The value to multiply by.

Returns

UpdateBuilder<TDocument>

The builder (so method calls can be chained).

Mul(Expression<Func<TDocument, long>>, long)

Multiplies the named element by a value (see $mul).

public static UpdateBuilder<TDocument> Mul(Expression<Func<TDocument, long>> memberExpression, long value)

Parameters

memberExpression Expression<Func<TDocument, long>>

The member expression.

value long

The value to multiply by.

Returns

UpdateBuilder<TDocument>

The builder (so method calls can be chained).

PopFirst<TValue>(Expression<Func<TDocument, IEnumerable<TValue>>>)

Removes the first value from the named array element (see $pop).

public static UpdateBuilder<TDocument> PopFirst<TValue>(Expression<Func<TDocument, IEnumerable<TValue>>> memberExpression)

Parameters

memberExpression Expression<Func<TDocument, IEnumerable<TValue>>>

The member expression.

Returns

UpdateBuilder<TDocument>

The builder (so method calls can be chained).

Type Parameters

TValue

The type of the enumerable member values.

PopLast<TValue>(Expression<Func<TDocument, IEnumerable<TValue>>>)

Removes the last value from the named array element (see $pop).

public static UpdateBuilder<TDocument> PopLast<TValue>(Expression<Func<TDocument, IEnumerable<TValue>>> memberExpression)

Parameters

memberExpression Expression<Func<TDocument, IEnumerable<TValue>>>

The member expression.

Returns

UpdateBuilder<TDocument>

The builder (so method calls can be chained).

Type Parameters

TValue

The type of the enumerable member values.

PullAll<TValue>(Expression<Func<TDocument, IEnumerable<TValue>>>, IEnumerable<TValue>)

Removes all values from the named array element that are equal to any of a list of values (see $pullAll).

public static UpdateBuilder<TDocument> PullAll<TValue>(Expression<Func<TDocument, IEnumerable<TValue>>> memberExpression, IEnumerable<TValue> values)

Parameters

memberExpression Expression<Func<TDocument, IEnumerable<TValue>>>

The member expression.

values IEnumerable<TValue>

The values to remove.

Returns

UpdateBuilder<TDocument>

The builder (so method calls can be chained).

Type Parameters

TValue

The type of the enumerable member values.

Pull<TValue>(Expression<Func<TDocument, IEnumerable<TValue>>>, Func<QueryBuilder<TValue>, IMongoQuery>)

Removes all values from the named array element that match some query (see $pull).

public static UpdateBuilder<TDocument> Pull<TValue>(Expression<Func<TDocument, IEnumerable<TValue>>> memberExpression, Func<QueryBuilder<TValue>, IMongoQuery> elementQueryBuilderFunction)

Parameters

memberExpression Expression<Func<TDocument, IEnumerable<TValue>>>

The member expression.

elementQueryBuilderFunction Func<QueryBuilder<TValue>, IMongoQuery>

A function that builds a query using the supplied query builder.

Returns

UpdateBuilder<TDocument>

The builder (so method calls can be chained).

Type Parameters

TValue

The type of the enumerable member values.

Pull<TValue>(Expression<Func<TDocument, IEnumerable<TValue>>>, TValue)

Removes all values from the named array element that are equal to some value (see $pull).

public static UpdateBuilder<TDocument> Pull<TValue>(Expression<Func<TDocument, IEnumerable<TValue>>> memberExpression, TValue value)

Parameters

memberExpression Expression<Func<TDocument, IEnumerable<TValue>>>

The member expression.

value TValue

The value to remove.

Returns

UpdateBuilder<TDocument>

The builder (so method calls can be chained).

Type Parameters

TValue

The type of the enumerable member values.

PushAll<TValue>(Expression<Func<TDocument, IEnumerable<TValue>>>, IEnumerable<TValue>)

Adds a list of values to the end of the named array element (see $pushAll).

public static UpdateBuilder<TDocument> PushAll<TValue>(Expression<Func<TDocument, IEnumerable<TValue>>> memberExpression, IEnumerable<TValue> values)

Parameters

memberExpression Expression<Func<TDocument, IEnumerable<TValue>>>

The member expression.

values IEnumerable<TValue>

The values to add to the end of the array.

Returns

UpdateBuilder<TDocument>

The builder (so method calls can be chained).

Type Parameters

TValue

The type of the enumerable member values.

PushEach<TValue>(Expression<Func<TDocument, IEnumerable<TValue>>>, PushEachOptions, IEnumerable<TValue>)

Adds a list of values to the end of the named array element (see $push and $each).

public static UpdateBuilder<TDocument> PushEach<TValue>(Expression<Func<TDocument, IEnumerable<TValue>>> memberExpression, PushEachOptions options, IEnumerable<TValue> values)

Parameters

memberExpression Expression<Func<TDocument, IEnumerable<TValue>>>

The member expression.

options PushEachOptions

The options.

values IEnumerable<TValue>

The values to add to the end of the array.

Returns

UpdateBuilder<TDocument>

The builder (so method calls can be chained).

Type Parameters

TValue

The type of the value.

PushEach<TValue>(Expression<Func<TDocument, IEnumerable<TValue>>>, Action<PushEachOptionsBuilder<TValue>>, IEnumerable<TValue>)

Adds a list of values to the end of the named array element (see $push and $each).

public static UpdateBuilder<TDocument> PushEach<TValue>(Expression<Func<TDocument, IEnumerable<TValue>>> memberExpression, Action<PushEachOptionsBuilder<TValue>> options, IEnumerable<TValue> values)

Parameters

memberExpression Expression<Func<TDocument, IEnumerable<TValue>>>

The member expression.

options Action<PushEachOptionsBuilder<TValue>>

The options.

values IEnumerable<TValue>

The values to add to the end of the array.

Returns

UpdateBuilder<TDocument>

The builder (so method calls can be chained).

Type Parameters

TValue

The type of the value.

PushEach<TValue>(Expression<Func<TDocument, IEnumerable<TValue>>>, IEnumerable<TValue>)

Adds a list of values to the end of the named array element (see $push and $each).

public static UpdateBuilder<TDocument> PushEach<TValue>(Expression<Func<TDocument, IEnumerable<TValue>>> memberExpression, IEnumerable<TValue> values)

Parameters

memberExpression Expression<Func<TDocument, IEnumerable<TValue>>>

The member expression.

values IEnumerable<TValue>

The values to add to the end of the array.

Returns

UpdateBuilder<TDocument>

The builder (so method calls can be chained).

Type Parameters

TValue

The type of the value.

Push<TValue>(Expression<Func<TDocument, IEnumerable<TValue>>>, TValue)

Adds a value to the end of the named array element (see $push).

public static UpdateBuilder<TDocument> Push<TValue>(Expression<Func<TDocument, IEnumerable<TValue>>> memberExpression, TValue value)

Parameters

memberExpression Expression<Func<TDocument, IEnumerable<TValue>>>

The member expression.

value TValue

The value to add to the end of the array.

Returns

UpdateBuilder<TDocument>

The builder (so method calls can be chained).

Type Parameters

TValue

The type of the enumerable member values.

Replace(TDocument)

Replaces the entire document with a new document (the _id must remain the same).

public static IMongoUpdate Replace(TDocument document)

Parameters

document TDocument

The replacement document.

Returns

IMongoUpdate

An UpdateWrapper.

SetOnInsert<TMember>(Expression<Func<TDocument, TMember>>, TMember)

Sets the value of the named element to the specified value only when an insert occurs as part of an upsert operation (see $setOnInsert).

public static UpdateBuilder<TDocument> SetOnInsert<TMember>(Expression<Func<TDocument, TMember>> memberExpression, TMember value)

Parameters

memberExpression Expression<Func<TDocument, TMember>>

The member expression.

value TMember

The new value.

Returns

UpdateBuilder<TDocument>

The builder (so method calls can be chained).

Type Parameters

TMember

The type of the member.

Set<TMember>(Expression<Func<TDocument, TMember>>, TMember)

Sets the value of the named element to a new value (see $set).

public static UpdateBuilder<TDocument> Set<TMember>(Expression<Func<TDocument, TMember>> memberExpression, TMember value)

Parameters

memberExpression Expression<Func<TDocument, TMember>>

The member expression.

value TMember

The new value.

Returns

UpdateBuilder<TDocument>

The builder (so method calls can be chained).

Type Parameters

TMember

The type of the member.

Unset<TMember>(Expression<Func<TDocument, TMember>>)

Removes the named element from the document (see $unset).

public static UpdateBuilder<TDocument> Unset<TMember>(Expression<Func<TDocument, TMember>> memberExpression)

Parameters

memberExpression Expression<Func<TDocument, TMember>>

The member expression.

Returns

UpdateBuilder<TDocument>

The builder (so method calls can be chained).

Type Parameters

TMember

The type of the member.