Class Replace<T>
Represents an UpdateOne command, which can replace the first matched document with a given entity
TIP: Specify a filter first with the .Match(). Then set entity with .WithEntity() and finally call .Execute() to run the command.
public class Replace<T> where T : IEntity
Type Parameters
TAny class that implements IEntity
- Inheritance
-
Replace<T>
- Inherited Members
Methods
AddToQueue()
Queue up a replace command for bulk execution later.
public Replace<T> AddToQueue()
Returns
- Replace<T>
ExecuteAsync(CancellationToken)
Run the replace command in MongoDB.
public Task<ReplaceOneResult> ExecuteAsync(CancellationToken cancellation = default)
Parameters
cancellationCancellationTokenAn optional cancellation token
Returns
- Task<ReplaceOneResult>
IgnoreGlobalFilters()
Specify that this operation should ignore any global filters
public Replace<T> IgnoreGlobalFilters()
Returns
- Replace<T>
Match(FilterDefinition<T>)
Specify the matching criteria with a filter definition
public Replace<T> Match(FilterDefinition<T> filterDefinition)
Parameters
filterDefinitionFilterDefinition<T>A filter definition
Returns
- Replace<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 Replace<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
- Replace<T>
Match(Template)
Specify the matching criteria with a template
public Replace<T> Match(Template template)
Parameters
templateTemplateA Template with a find query
Returns
- Replace<T>
Match(Func<FilterDefinitionBuilder<T>, FilterDefinition<T>>)
Specify the matching criteria with a filter expression
public Replace<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
- Replace<T>
Match(Expression<Func<T, bool>>)
Specify the matching criteria with a lambda expression
public Replace<T> Match(Expression<Func<T, bool>> expression)
Parameters
expressionExpression<Func<T, bool>>x => x.Property == Value
Returns
- Replace<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 Replace<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
- Replace<T>
MatchExpression(Template)
Specify the matching criteria with a Template
public Replace<T> MatchExpression(Template template)
Parameters
templateTemplateA Template object
Returns
- Replace<T>
MatchExpression(string)
Specify the matching criteria with an aggregation expression (i.e. $expr)
public Replace<T> MatchExpression(string expression)
Parameters
expressionstring{ $gt: ['$Property1', '$Property2'] }
Returns
- Replace<T>
MatchID(object)
Specify an IEntity ID as the matching criteria
public Replace<T> MatchID(object ID)
Parameters
IDobjectA unique IEntity ID
Returns
- Replace<T>
MatchString(string)
Specify the matching criteria with a JSON string
public Replace<T> MatchString(string jsonString)
Parameters
jsonStringstring{ Title : 'The Power Of Now' }
Returns
- Replace<T>
Option(Action<ReplaceOptions>)
Specify an option for this replace command (use multiple times if needed)
TIP: Setting options is not required
public Replace<T> Option(Action<ReplaceOptions> option)
Parameters
optionAction<ReplaceOptions>x => x.OptionName = OptionValue
Returns
- Replace<T>
WithEntity(T)
Supply the entity to replace the first matched document with
TIP: If the entity ID is empty, a new ID will be generated before being stored
public Replace<T> WithEntity(T entity)
Parameters
entityT
Returns
- Replace<T>