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.
Inherited Members
Namespace: MongoDB.Entities
Assembly: MongoDB.Entities.dll
Syntax
public class UpdateAndGet<T, TProjection> : UpdateBase<T> where T : IEntity
Type Parameters
Name | Description |
---|---|
T | Any class that implements IEntity |
TProjection | The type to project to |
Methods
ExecuteAsync(CancellationToken)
Run the update command in MongoDB and retrieve the first document modified
Declaration
public async Task<TProjection> ExecuteAsync(CancellationToken cancellation = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellation | An optional cancellation token |
Returns
Type | Description |
---|---|
Task<TProjection> |
ExecutePipelineAsync(CancellationToken)
Run the update command with pipeline stages and retrieve the first document modified
Declaration
public Task<TProjection> ExecutePipelineAsync(CancellationToken cancellation = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellation | An optional cancellation token |
Returns
Type | Description |
---|---|
Task<TProjection> |
IgnoreGlobalFilters()
Specify that this operation should ignore any global filters
Declaration
public UpdateAndGet<T, TProjection> IgnoreGlobalFilters()
Returns
Type | Description |
---|---|
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.
Declaration
public UpdateAndGet<T, TProjection> IncludeRequiredProps()
Returns
Type | Description |
---|---|
UpdateAndGet<T, TProjection> |
Match(FilterDefinition<T>)
Specify the matching criteria with a filter definition
Declaration
public UpdateAndGet<T, TProjection> Match(FilterDefinition<T> filterDefinition)
Parameters
Type | Name | Description |
---|---|---|
FilterDefinition<T> | filterDefinition | A filter definition |
Returns
Type | Description |
---|---|
UpdateAndGet<T, TProjection> |
Match(Search, String, Boolean, Boolean, 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
Declaration
public UpdateAndGet<T, TProjection> Match(Search searchType, string searchTerm, bool caseSensitive = false, bool diacriticSensitive = false, string language = null)
Parameters
Type | Name | Description |
---|---|---|
Search | searchType | The type of text matching to do |
String | searchTerm | The search term |
Boolean | caseSensitive | Case sensitivity of the search (optional) |
Boolean | diacriticSensitive | Diacritic sensitivity of the search (optional) |
String | language | The language for the search (optional) |
Returns
Type | Description |
---|---|
UpdateAndGet<T, TProjection> |
Match(Template)
Specify the matching criteria with a template
Declaration
public UpdateAndGet<T, TProjection> Match(Template template)
Parameters
Type | Name | Description |
---|---|---|
Template | template | A Template with a find query |
Returns
Type | Description |
---|---|
UpdateAndGet<T, TProjection> |
Match(Func<FilterDefinitionBuilder<T>, FilterDefinition<T>>)
Specify the matching criteria with a filter expression
Declaration
public UpdateAndGet<T, TProjection> Match(Func<FilterDefinitionBuilder<T>, FilterDefinition<T>> filter)
Parameters
Type | Name | Description |
---|---|---|
Func<FilterDefinitionBuilder<T>, FilterDefinition<T>> | filter | f => f.Eq(x => x.Prop, Value) & f.Gt(x => x.Prop, Value) |
Returns
Type | Description |
---|---|
UpdateAndGet<T, TProjection> |
Match(Expression<Func<T, Boolean>>)
Specify the matching criteria with a lambda expression
Declaration
public UpdateAndGet<T, TProjection> Match(Expression<Func<T, bool>> expression)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, Boolean>> | expression | x => x.Property == Value |
Returns
Type | Description |
---|---|
UpdateAndGet<T, TProjection> |
Match(Expression<Func<T, Object>>, Coordinates2D, Nullable<Double>, Nullable<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
Declaration
public UpdateAndGet<T, TProjection> Match(Expression<Func<T, object>> coordinatesProperty, Coordinates2D nearCoordinates, double? maxDistance = null, double? minDistance = null)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, Object>> | coordinatesProperty | The property where 2DCoordinates are stored |
Coordinates2D | nearCoordinates | The search point |
Nullable<Double> | maxDistance | Maximum distance in meters from the search point |
Nullable<Double> | minDistance | Minimum distance in meters from the search point |
Returns
Type | Description |
---|---|
UpdateAndGet<T, TProjection> |
MatchExpression(Template)
Specify the matching criteria with a Template
Declaration
public UpdateAndGet<T, TProjection> MatchExpression(Template template)
Parameters
Type | Name | Description |
---|---|---|
Template | template | A Template object |
Returns
Type | Description |
---|---|
UpdateAndGet<T, TProjection> |
MatchExpression(String)
Specify the matching criteria with an aggregation expression (i.e. $expr)
Declaration
public UpdateAndGet<T, TProjection> MatchExpression(string expression)
Parameters
Type | Name | Description |
---|---|---|
String | expression | { $gt: ['$Property1', '$Property2'] } |
Returns
Type | Description |
---|---|
UpdateAndGet<T, TProjection> |
MatchID(String)
Specify an IEntity ID as the matching criteria
Declaration
public UpdateAndGet<T, TProjection> MatchID(string ID)
Parameters
Type | Name | Description |
---|---|---|
String | ID | A unique IEntity ID |
Returns
Type | Description |
---|---|
UpdateAndGet<T, TProjection> |
MatchString(String)
Specify the matching criteria with a JSON string
Declaration
public UpdateAndGet<T, TProjection> MatchString(string jsonString)
Parameters
Type | Name | Description |
---|---|---|
String | jsonString | { Title : 'The Power Of Now' } |
Returns
Type | Description |
---|---|
UpdateAndGet<T, TProjection> |
Modify(Template)
Specify an update with a Template to modify the Entities (use multiple times if needed)
Declaration
public UpdateAndGet<T, TProjection> Modify(Template template)
Parameters
Type | Name | Description |
---|---|---|
Template | template | A Template with a single update |
Returns
Type | Description |
---|---|
UpdateAndGet<T, TProjection> |
Modify(Func<UpdateDefinitionBuilder<T>, UpdateDefinition<T>>)
Specify the update definition builder operation to modify the Entities (use multiple times if needed)
Declaration
public UpdateAndGet<T, TProjection> Modify(Func<UpdateDefinitionBuilder<T>, UpdateDefinition<T>> operation)
Parameters
Type | Name | Description |
---|---|---|
Func<UpdateDefinitionBuilder<T>, UpdateDefinition<T>> | operation | b => b.Inc(x => x.PropName, Value) |
Returns
Type | Description |
---|---|
UpdateAndGet<T, TProjection> |
Modify(String)
Specify an update (json string) to modify the Entities (use multiple times if needed)
Declaration
public UpdateAndGet<T, TProjection> Modify(string update)
Parameters
Type | Name | Description |
---|---|---|
String | update | { \(set: { 'RootProp.\)[x].SubProp' : 321 } } |
Returns
Type | Description |
---|---|
UpdateAndGet<T, TProjection> |
Modify<TProp>(Expression<Func<T, TProp>>, TProp)
Specify the property and it's value to modify (use multiple times if needed)
Declaration
public UpdateAndGet<T, TProjection> Modify<TProp>(Expression<Func<T, TProp>> property, TProp value)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, TProp>> | property | x => x.Property |
TProp | value | The value to set on the property |
Returns
Type | Description |
---|---|
UpdateAndGet<T, TProjection> |
Type Parameters
Name | Description |
---|---|
TProp |
ModifyExcept(Expression<Func<T, Object>>, T)
Modify all EXCEPT the specified properties with the values from a given entity instance.
Declaration
public UpdateAndGet<T, TProjection> ModifyExcept(Expression<Func<T, object>> members, T entity)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, Object>> | members | Supply a new expression with the properties to exclude. Ex: |
T | entity | The entity instance to read the corresponding values from |
Returns
Type | Description |
---|---|
UpdateAndGet<T, TProjection> |
ModifyOnly(Expression<Func<T, Object>>, T)
Modify ONLY the specified properties with the values from a given entity instance.
Declaration
public UpdateAndGet<T, TProjection> ModifyOnly(Expression<Func<T, object>> members, T entity)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, Object>> | members | A new expression with the properties to include. Ex: |
T | entity | The entity instance to read the corresponding values from |
Returns
Type | Description |
---|---|
UpdateAndGet<T, TProjection> |
ModifyWith(T)
Modify ALL properties with the values from the supplied entity instance.
Declaration
public UpdateAndGet<T, TProjection> ModifyWith(T entity)
Parameters
Type | Name | Description |
---|---|---|
T | entity | The entity instance to read the property values from |
Returns
Type | Description |
---|---|
UpdateAndGet<T, TProjection> |
Option(Action<FindOneAndUpdateOptions<T, TProjection>>)
Specify an option for this update command (use multiple times if needed)
TIP: Setting options is not required
Declaration
public UpdateAndGet<T, TProjection> Option(Action<FindOneAndUpdateOptions<T, TProjection>> option)
Parameters
Type | Name | Description |
---|---|---|
Action<FindOneAndUpdateOptions<T, TProjection>> | option | x => x.OptionName = OptionValue |
Returns
Type | Description |
---|---|
UpdateAndGet<T, TProjection> |
Project(Func<ProjectionDefinitionBuilder<T>, ProjectionDefinition<T, TProjection>>)
Specify how to project the results using a projection expression
Declaration
public UpdateAndGet<T, TProjection> Project(Func<ProjectionDefinitionBuilder<T>, ProjectionDefinition<T, TProjection>> projection)
Parameters
Type | Name | Description |
---|---|---|
Func<ProjectionDefinitionBuilder<T>, ProjectionDefinition<T, TProjection>> | projection | p => p.Include("Prop1").Exclude("Prop2") |
Returns
Type | Description |
---|---|
UpdateAndGet<T, TProjection> |
Project(Expression<Func<T, TProjection>>)
Specify how to project the results using a lambda expression
Declaration
public UpdateAndGet<T, TProjection> Project(Expression<Func<T, TProjection>> expression)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, TProjection>> | expression | x => new Test { PropName = x.Prop } |
Returns
Type | Description |
---|---|
UpdateAndGet<T, TProjection> |
WithArrayFilter(Template)
Specify a single array filter using a Template to target nested entities for updates
Declaration
public UpdateAndGet<T, TProjection> WithArrayFilter(Template template)
Parameters
Type | Name | Description |
---|---|---|
Template | template |
Returns
Type | Description |
---|---|
UpdateAndGet<T, TProjection> |
WithArrayFilter(String)
Specify an array filter to target nested entities for updates (use multiple times if needed).
Declaration
public UpdateAndGet<T, TProjection> WithArrayFilter(string filter)
Parameters
Type | Name | Description |
---|---|---|
String | filter | { 'x.SubProp': { $gte: 123 } } |
Returns
Type | Description |
---|---|
UpdateAndGet<T, TProjection> |
WithArrayFilters(Template)
Specify multiple array filters with a Template to target nested entities for updates.
Declaration
public UpdateAndGet<T, TProjection> WithArrayFilters(Template template)
Parameters
Type | Name | Description |
---|---|---|
Template | template | The template with an array [...] of filters |
Returns
Type | Description |
---|---|
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.
Declaration
public UpdateAndGet<T, TProjection> WithPipeline(Template template)
Parameters
Type | Name | Description |
---|---|---|
Template | template | A Template object containing multiple pipeline stages |
Returns
Type | Description |
---|---|
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.
Declaration
public UpdateAndGet<T, TProjection> WithPipelineStage(Template template)
Parameters
Type | Name | Description |
---|---|---|
Template | template | A Template object containing a pipeline stage |
Returns
Type | Description |
---|---|
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.
Declaration
public UpdateAndGet<T, TProjection> WithPipelineStage(string stage)
Parameters
Type | Name | Description |
---|---|---|
String | stage | { $set: { FullName: { $concat: ['$Name', ' ', '$Surname'] } } } |
Returns
Type | Description |
---|---|
UpdateAndGet<T, TProjection> |