Class UpdateAndGet<T, TProjection>
Update and retrieve the first document that was updated.
TIP: Specify a filter first with the .Match(). Then set property values with .Modify() and finally call .Execute() to run the command.
public class UpdateAndGet<T, TProjection> : UpdateBase<T> where T : IEntity
Type Parameters
TAny class that implements IEntity
TProjectionThe type to project to
- Inheritance
-
UpdateBase<T>UpdateAndGet<T, TProjection>
- Derived
- Inherited Members
Methods
ExecuteAsync(CancellationToken)
Run the update command in MongoDB and retrieve the first document modified
public Task<TProjection?> ExecuteAsync(CancellationToken cancellation = default)
Parameters
cancellationCancellationTokenAn optional cancellation token
Returns
- Task<TProjection>
ExecutePipelineAsync(CancellationToken)
Run the update command with pipeline stages and retrieve the first document modified
public Task<TProjection?> ExecutePipelineAsync(CancellationToken cancellation = default)
Parameters
cancellationCancellationTokenAn optional cancellation token
Returns
- Task<TProjection>
IgnoreGlobalFilters()
Specify that this operation should ignore any global filters
public UpdateAndGet<T, TProjection> IgnoreGlobalFilters()
Returns
- UpdateAndGet<T, TProjection>
IncludeRequiredProps()
Specify to automatically include all properties marked with [BsonRequired] attribute on the entity in the final projection.
HINT: this method should only be called after the .Project() method.
public UpdateAndGet<T, TProjection> IncludeRequiredProps()
Returns
- UpdateAndGet<T, TProjection>
Match(FilterDefinition<T>)
Specify the matching criteria with a filter definition
public UpdateAndGet<T, TProjection> Match(FilterDefinition<T> filterDefinition)
Parameters
filterDefinitionFilterDefinition<T>A filter definition
Returns
- UpdateAndGet<T, TProjection>
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 UpdateAndGet<T, TProjection> 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
- UpdateAndGet<T, TProjection>
Match(Template)
Specify the matching criteria with a template
public UpdateAndGet<T, TProjection> Match(Template template)
Parameters
templateTemplateA Template with a find query
Returns
- UpdateAndGet<T, TProjection>
Match(Func<FilterDefinitionBuilder<T>, FilterDefinition<T>>)
Specify the matching criteria with a filter expression
public UpdateAndGet<T, TProjection> 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
- UpdateAndGet<T, TProjection>
Match(Expression<Func<T, bool>>)
Specify the matching criteria with a lambda expression
public UpdateAndGet<T, TProjection> Match(Expression<Func<T, bool>> expression)
Parameters
expressionExpression<Func<T, bool>>x => x.Property == Value
Returns
- UpdateAndGet<T, TProjection>
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 UpdateAndGet<T, TProjection> 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
- UpdateAndGet<T, TProjection>
MatchExpression(Template)
Specify the matching criteria with a Template
public UpdateAndGet<T, TProjection> MatchExpression(Template template)
Parameters
templateTemplateA Template object
Returns
- UpdateAndGet<T, TProjection>
MatchExpression(string)
Specify the matching criteria with an aggregation expression (i.e. $expr)
public UpdateAndGet<T, TProjection> MatchExpression(string expression)
Parameters
expressionstring{ $gt: ['$Property1', '$Property2'] }
Returns
- UpdateAndGet<T, TProjection>
MatchID(object)
Specify an IEntity ID as the matching criteria
public UpdateAndGet<T, TProjection> MatchID(object ID)
Parameters
IDobjectA unique IEntity ID
Returns
- UpdateAndGet<T, TProjection>
MatchString(string)
Specify the matching criteria with a JSON string
public UpdateAndGet<T, TProjection> MatchString(string jsonString)
Parameters
jsonStringstring{ Title : 'The Power Of Now' }
Returns
- UpdateAndGet<T, TProjection>
Modify(Template)
Specify an update with a Template to modify the Entities (use multiple times if needed)
public UpdateAndGet<T, TProjection> Modify(Template template)
Parameters
templateTemplateA Template with a single update
Returns
- UpdateAndGet<T, TProjection>
Modify(Func<UpdateDefinitionBuilder<T>, UpdateDefinition<T>>)
Specify the update definition builder operation to modify the Entities (use multiple times if needed)
public UpdateAndGet<T, TProjection> Modify(Func<UpdateDefinitionBuilder<T>, UpdateDefinition<T>> operation)
Parameters
operationFunc<UpdateDefinitionBuilder<T>, UpdateDefinition<T>>b => b.Inc(x => x.PropName, Value)
Returns
- UpdateAndGet<T, TProjection>
Modify(string)
Specify an update (json string) to modify the Entities (use multiple times if needed)
public UpdateAndGet<T, TProjection> Modify(string update)
Parameters
updatestring{ \(set: { 'RootProp.\)[x].SubProp' : 321 } }
Returns
- UpdateAndGet<T, TProjection>
ModifyExcept(Expression<Func<T, object?>>, T)
Modify all EXCEPT the specified properties with the values from a given entity instance.
public UpdateAndGet<T, TProjection> 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
- UpdateAndGet<T, TProjection>
ModifyOnly(Expression<Func<T, object?>>, T)
Modify ONLY the specified properties with the values from a given entity instance.
public UpdateAndGet<T, TProjection> 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
- UpdateAndGet<T, TProjection>
ModifyWith(T)
Modify ALL properties with the values from the supplied entity instance.
public UpdateAndGet<T, TProjection> ModifyWith(T entity)
Parameters
entityTThe entity instance to read the property values from
Returns
- UpdateAndGet<T, TProjection>
Modify<TProp>(Expression<Func<T, TProp>>, TProp)
Specify the property and it's value to modify (use multiple times if needed)
public UpdateAndGet<T, TProjection> 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
- UpdateAndGet<T, TProjection>
Type Parameters
TProp
Option(Action<FindOneAndUpdateOptions<T, TProjection>>)
Specify an option for this update command (use multiple times if needed)
TIP: Setting options is not required
public UpdateAndGet<T, TProjection> Option(Action<FindOneAndUpdateOptions<T, TProjection>> option)
Parameters
optionAction<FindOneAndUpdateOptions<T, TProjection>>x => x.OptionName = OptionValue
Returns
- UpdateAndGet<T, TProjection>
Project(Func<ProjectionDefinitionBuilder<T>, ProjectionDefinition<T, TProjection>>)
Specify how to project the results using a projection expression
public UpdateAndGet<T, TProjection> Project(Func<ProjectionDefinitionBuilder<T>, ProjectionDefinition<T, TProjection>> projection)
Parameters
projectionFunc<ProjectionDefinitionBuilder<T>, ProjectionDefinition<T, TProjection>>p => p.Include("Prop1").Exclude("Prop2")
Returns
- UpdateAndGet<T, TProjection>
Project(Expression<Func<T, TProjection>>)
Specify how to project the results using a lambda expression
public UpdateAndGet<T, TProjection> Project(Expression<Func<T, TProjection>> expression)
Parameters
expressionExpression<Func<T, TProjection>>x => new Test { PropName = x.Prop }
Returns
- UpdateAndGet<T, TProjection>
WithArrayFilter(Template)
Specify a single array filter using a Template to target nested entities for updates
public UpdateAndGet<T, TProjection> WithArrayFilter(Template template)
Parameters
templateTemplate
Returns
- UpdateAndGet<T, TProjection>
WithArrayFilter(string)
Specify an array filter to target nested entities for updates (use multiple times if needed).
public UpdateAndGet<T, TProjection> WithArrayFilter(string filter)
Parameters
filterstring{ 'x.SubProp': { $gte: 123 } }
Returns
- UpdateAndGet<T, TProjection>
WithArrayFilters(Template)
Specify multiple array filters with a Template to target nested entities for updates.
public UpdateAndGet<T, TProjection> WithArrayFilters(Template template)
Parameters
templateTemplateThe template with an array [...] of filters
Returns
- UpdateAndGet<T, TProjection>
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 UpdateAndGet<T, TProjection> WithPipeline(Template template)
Parameters
templateTemplateA Template object containing multiple pipeline stages
Returns
- UpdateAndGet<T, TProjection>
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 UpdateAndGet<T, TProjection> WithPipelineStage(Template template)
Parameters
templateTemplateA Template object containing a pipeline stage
Returns
- UpdateAndGet<T, TProjection>
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 UpdateAndGet<T, TProjection> WithPipelineStage(string stage)
Parameters
stagestring{ $set: { FullName: { $concat: ['$Name', ' ', '$Surname'] } } }
Returns
- UpdateAndGet<T, TProjection>