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.
Inheritance
Inherited Members
Namespace: MongoDB.Entities
Assembly: MongoDB.Entities.dll
Syntax
public class Replace<T>
where T : IEntity
Type Parameters
Name | Description |
---|---|
T | Any class that implements IEntity |
Methods
AddToQueue()
Queue up a replace command for bulk execution later.
Declaration
public Replace<T> AddToQueue()
Returns
Type | Description |
---|---|
Replace<T> |
ExecuteAsync(CancellationToken)
Run the replace command in MongoDB.
Declaration
public async Task<ReplaceOneResult> ExecuteAsync(CancellationToken cancellation = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellation | An optional cancellation token |
Returns
Type | Description |
---|---|
Task<ReplaceOneResult> |
IgnoreGlobalFilters()
Specify that this operation should ignore any global filters
Declaration
public Replace<T> IgnoreGlobalFilters()
Returns
Type | Description |
---|---|
Replace<T> |
Match(FilterDefinition<T>)
Specify the matching criteria with a filter definition
Declaration
public Replace<T> Match(FilterDefinition<T> filterDefinition)
Parameters
Type | Name | Description |
---|---|---|
FilterDefinition<T> | filterDefinition | A filter definition |
Returns
Type | Description |
---|---|
Replace<T> |
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 Replace<T> 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 |
---|---|
Replace<T> |
Match(Template)
Specify the matching criteria with a template
Declaration
public Replace<T> Match(Template template)
Parameters
Type | Name | Description |
---|---|---|
Template | template | A Template with a find query |
Returns
Type | Description |
---|---|
Replace<T> |
Match(Func<FilterDefinitionBuilder<T>, FilterDefinition<T>>)
Specify the matching criteria with a filter expression
Declaration
public Replace<T> 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 |
---|---|
Replace<T> |
Match(Expression<Func<T, Boolean>>)
Specify the matching criteria with a lambda expression
Declaration
public Replace<T> Match(Expression<Func<T, bool>> expression)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, Boolean>> | expression | x => x.Property == Value |
Returns
Type | Description |
---|---|
Replace<T> |
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 Replace<T> 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 |
---|---|
Replace<T> |
MatchExpression(Template)
Specify the matching criteria with a Template
Declaration
public Replace<T> MatchExpression(Template template)
Parameters
Type | Name | Description |
---|---|---|
Template | template | A Template object |
Returns
Type | Description |
---|---|
Replace<T> |
MatchExpression(String)
Specify the matching criteria with an aggregation expression (i.e. $expr)
Declaration
public Replace<T> MatchExpression(string expression)
Parameters
Type | Name | Description |
---|---|---|
String | expression | { $gt: ['$Property1', '$Property2'] } |
Returns
Type | Description |
---|---|
Replace<T> |
MatchID(String)
Specify an IEntity ID as the matching criteria
Declaration
public Replace<T> MatchID(string ID)
Parameters
Type | Name | Description |
---|---|---|
String | ID | A unique IEntity ID |
Returns
Type | Description |
---|---|
Replace<T> |
MatchString(String)
Specify the matching criteria with a JSON string
Declaration
public Replace<T> MatchString(string jsonString)
Parameters
Type | Name | Description |
---|---|---|
String | jsonString | { Title : 'The Power Of Now' } |
Returns
Type | Description |
---|---|
Replace<T> |
Option(Action<ReplaceOptions>)
Specify an option for this replace command (use multiple times if needed)
TIP: Setting options is not required
Declaration
public Replace<T> Option(Action<ReplaceOptions> option)
Parameters
Type | Name | Description |
---|---|---|
Action<ReplaceOptions> | option | x => x.OptionName = OptionValue |
Returns
Type | Description |
---|---|
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
Declaration
public Replace<T> WithEntity(T entity)
Parameters
Type | Name | Description |
---|---|---|
T | entity |
Returns
Type | Description |
---|---|
Replace<T> |