Class Update<T>
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
TAny class that implements IEntity
- Inheritance
-
UpdateBase<T>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
cancellationCancellationTokenAn optional cancellation token
Returns
- Task<UpdateResult>
ExecutePipelineAsync(CancellationToken)
Run the update command with pipeline stages
public Task<UpdateResult> ExecutePipelineAsync(CancellationToken cancellation = default)
Parameters
cancellationCancellationTokenAn 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
filterDefinitionFilterDefinition<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
searchTypeSearchThe type of text matching to do
searchTermstringThe search term
caseSensitiveboolCase sensitivity of the search (optional)
diacriticSensitiveboolDiacritic sensitivity of the search (optional)
languagestringThe language for the search (optional)
Returns
- Update<T>
Match(Template)
Specify the matching criteria with a template
public Update<T> Match(Template template)
Parameters
templateTemplateA 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
filterFunc<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
expressionExpression<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
coordinatesPropertyExpression<Func<T, object>>The property where 2DCoordinates are stored
nearCoordinatesCoordinates2DThe search point
maxDistancedouble?Maximum distance in meters from the search point
minDistancedouble?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
templateTemplateA 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
expressionstring{ $gt: ['$Property1', '$Property2'] }
Returns
- Update<T>
MatchID(object)
Specify an IEntity ID as the matching criteria
public Update<T> MatchID(object ID)
Parameters
IDobjectA unique IEntity ID
Returns
- Update<T>
MatchString(string)
Specify the matching criteria with a JSON string
public Update<T> MatchString(string jsonString)
Parameters
jsonStringstring{ 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
templateTemplateA 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
operationFunc<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
updatestring{ \(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
membersExpression<Func<T, object>>Supply a new expression with the properties to exclude. Ex:
x => new { x.Prop1, x.Prop2 }entityTThe 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
membersExpression<Func<T, object>>A new expression with the properties to include. Ex:
x => new { x.PropOne, x.PropTwo }entityTThe 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
entityTThe 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
propertyExpression<Func<T, TProp>>x => x.Property
valueTPropThe 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
optionAction<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
templateTemplate
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
filterstring{ '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
templateTemplateThe 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
templateTemplateA 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
templateTemplateA 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
stagestring{ $set: { FullName: { $concat: ['$Name', ' ', '$Surname'] } } }
Returns
- Update<T>