Table of Contents

Class Update<T>

Namespace
MongoDB.Entities
Assembly
MongoDB.Entities.dll

Represents an update command

TIP: Specify a filter first with the .Match(). Then set property values with .Modify() and finally call .Execute() to run the command.

public class Update<T> : UpdateBase<T> where T : IEntity

Type Parameters

T

Any class that implements IEntity

Inheritance
Update<T>
Inherited Members

Methods

AddToQueue()

Queue up an update command for bulk execution later.

public Update<T> AddToQueue()

Returns

Update<T>

ExecuteAsync(CancellationToken)

Run the update command in MongoDB.

public Task<UpdateResult> ExecuteAsync(CancellationToken cancellation = default)

Parameters

cancellation CancellationToken

An optional cancellation token

Returns

Task<UpdateResult>

ExecutePipelineAsync(CancellationToken)

Run the update command with pipeline stages

public Task<UpdateResult> ExecutePipelineAsync(CancellationToken cancellation = default)

Parameters

cancellation CancellationToken

An optional cancellation token

Returns

Task<UpdateResult>

IgnoreGlobalFilters()

Specify that this operation should ignore any global filters

public Update<T> IgnoreGlobalFilters()

Returns

Update<T>

Match(FilterDefinition<T>)

Specify the matching criteria with a filter definition

public Update<T> Match(FilterDefinition<T> filterDefinition)

Parameters

filterDefinition FilterDefinition<T>

A filter definition

Returns

Update<T>

Match(Search, string, bool, bool, string?)

Specify a search term to find results from the text index of this particular collection.

TIP: Make sure to define a text index with DB.Index<T>() before searching

public Update<T> Match(Search searchType, string searchTerm, bool caseSensitive = false, bool diacriticSensitive = false, string? language = null)

Parameters

searchType Search

The type of text matching to do

searchTerm string

The search term

caseSensitive bool

Case sensitivity of the search (optional)

diacriticSensitive bool

Diacritic sensitivity of the search (optional)

language string

The language for the search (optional)

Returns

Update<T>

Match(Template)

Specify the matching criteria with a template

public Update<T> Match(Template template)

Parameters

template Template

A Template with a find query

Returns

Update<T>

Match(Func<FilterDefinitionBuilder<T>, FilterDefinition<T>>)

Specify the matching criteria with a filter expression

public Update<T> Match(Func<FilterDefinitionBuilder<T>, FilterDefinition<T>> filter)

Parameters

filter Func<FilterDefinitionBuilder<T>, FilterDefinition<T>>

f => f.Eq(x => x.Prop, Value) & f.Gt(x => x.Prop, Value)

Returns

Update<T>

Match(Expression<Func<T, bool>>)

Specify the matching criteria with a lambda expression

public Update<T> Match(Expression<Func<T, bool>> expression)

Parameters

expression Expression<Func<T, bool>>

x => x.Property == Value

Returns

Update<T>

Match(Expression<Func<T, object?>>, Coordinates2D, double?, double?)

Specify criteria for matching entities based on GeoSpatial data (longitude & latitude)

TIP: Make sure to define a Geo2DSphere index with DB.Index<T>() before searching

Note: DB.FluentGeoNear() supports more advanced options

public Update<T> Match(Expression<Func<T, object?>> coordinatesProperty, Coordinates2D nearCoordinates, double? maxDistance = null, double? minDistance = null)

Parameters

coordinatesProperty Expression<Func<T, object>>

The property where 2DCoordinates are stored

nearCoordinates Coordinates2D

The search point

maxDistance double?

Maximum distance in meters from the search point

minDistance double?

Minimum distance in meters from the search point

Returns

Update<T>

MatchExpression(Template)

Specify the matching criteria with a Template

public Update<T> MatchExpression(Template template)

Parameters

template Template

A Template object

Returns

Update<T>

MatchExpression(string)

Specify the matching criteria with an aggregation expression (i.e. $expr)

public Update<T> MatchExpression(string expression)

Parameters

expression string

{ $gt: ['$Property1', '$Property2'] }

Returns

Update<T>

MatchID(object)

Specify an IEntity ID as the matching criteria

public Update<T> MatchID(object ID)

Parameters

ID object

A unique IEntity ID

Returns

Update<T>

MatchString(string)

Specify the matching criteria with a JSON string

public Update<T> MatchString(string jsonString)

Parameters

jsonString string

{ Title : 'The Power Of Now' }

Returns

Update<T>

Modify(Template)

Specify an update with a Template to modify the Entities (use multiple times if needed)

public Update<T> Modify(Template template)

Parameters

template Template

A Template with a single update

Returns

Update<T>

Modify(Func<UpdateDefinitionBuilder<T>, UpdateDefinition<T>>)

Specify the update definition builder operation to modify the Entities (use multiple times if needed)

public Update<T> Modify(Func<UpdateDefinitionBuilder<T>, UpdateDefinition<T>> operation)

Parameters

operation Func<UpdateDefinitionBuilder<T>, UpdateDefinition<T>>

b => b.Inc(x => x.PropName, Value)

Returns

Update<T>

Modify(string)

Specify an update (json string) to modify the Entities (use multiple times if needed)

public Update<T> Modify(string update)

Parameters

update string

{ \(set: { 'RootProp.\)[x].SubProp' : 321 } }

Returns

Update<T>

ModifyExcept(Expression<Func<T, object?>>, T)

Modify all EXCEPT the specified properties with the values from a given entity instance.

public Update<T> ModifyExcept(Expression<Func<T, object?>> members, T entity)

Parameters

members Expression<Func<T, object>>

Supply a new expression with the properties to exclude. Ex: x => new { x.Prop1, x.Prop2 }

entity T

The entity instance to read the corresponding values from

Returns

Update<T>

ModifyOnly(Expression<Func<T, object?>>, T)

Modify ONLY the specified properties with the values from a given entity instance.

public Update<T> ModifyOnly(Expression<Func<T, object?>> members, T entity)

Parameters

members Expression<Func<T, object>>

A new expression with the properties to include. Ex: x => new { x.PropOne, x.PropTwo }

entity T

The entity instance to read the corresponding values from

Returns

Update<T>

ModifyWith(T)

Modify ALL properties with the values from the supplied entity instance.

public Update<T> ModifyWith(T entity)

Parameters

entity T

The entity instance to read the property values from

Returns

Update<T>

Modify<TProp>(Expression<Func<T, TProp>>, TProp)

Specify the property, and it's value to modify (use multiple times if needed)

public Update<T> Modify<TProp>(Expression<Func<T, TProp>> property, TProp value)

Parameters

property Expression<Func<T, TProp>>

x => x.Property

value TProp

The value to set on the property

Returns

Update<T>

Type Parameters

TProp

Option(Action<UpdateOptions>)

Specify an option for this update command (use multiple times if needed)

TIP: Setting options is not required

public Update<T> Option(Action<UpdateOptions> option)

Parameters

option Action<UpdateOptions>

x => x.OptionName = OptionValue

Returns

Update<T>

WithArrayFilter(Template)

Specify a single array filter using a Template to target nested entities for updates

public Update<T> WithArrayFilter(Template template)

Parameters

template Template

Returns

Update<T>

WithArrayFilter(string)

Specify an array filter to target nested entities for updates (use multiple times if needed).

public Update<T> WithArrayFilter(string filter)

Parameters

filter string

{ 'x.SubProp': { $gte: 123 } }

Returns

Update<T>

WithArrayFilters(Template)

Specify multiple array filters with a Template to target nested entities for updates.

public Update<T> WithArrayFilters(Template template)

Parameters

template Template

The template with an array [...] of filters

Returns

Update<T>

WithPipeline(Template)

Specify an update pipeline with multiple stages using a Template to modify the Entities.

NOTE: pipeline updates and regular updates cannot be used together.

public Update<T> WithPipeline(Template template)

Parameters

template Template

A Template object containing multiple pipeline stages

Returns

Update<T>

WithPipelineStage(Template)

Specify an update pipeline stage using a Template to modify the Entities (use multiple times if needed)

NOTE: pipeline updates and regular updates cannot be used together.

public Update<T> WithPipelineStage(Template template)

Parameters

template Template

A Template object containing a pipeline stage

Returns

Update<T>

WithPipelineStage(string)

Specify an update pipeline stage to modify the Entities (use multiple times if needed)

NOTE: pipeline updates and regular updates cannot be used together.

public Update<T> WithPipelineStage(string stage)

Parameters

stage string

{ $set: { FullName: { $concat: ['$Name', ' ', '$Surname'] } } }

Returns

Update<T>