Table of Contents

Class Replace<T>

Namespace
MongoDB.Entities
Assembly
MongoDB.Entities.dll

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

T

Any 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

cancellation CancellationToken

An 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

filterDefinition FilterDefinition<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

searchType Search

The type of text matching to do

searchTerm string

The search term

caseSensitive bool

Case sensitivity of the search (optional)

diacriticSensitive bool

Diacritic sensitivity of the search (optional)

language string

The language for the search (optional)

Returns

Replace<T>

Match(Template)

Specify the matching criteria with a template

public Replace<T> Match(Template template)

Parameters

template Template

A 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

filter Func<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

expression Expression<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

coordinatesProperty Expression<Func<T, object>>

The property where 2DCoordinates are stored

nearCoordinates Coordinates2D

The search point

maxDistance double?

Maximum distance in meters from the search point

minDistance double?

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

template Template

A 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

expression string

{ $gt: ['$Property1', '$Property2'] }

Returns

Replace<T>

MatchID(object)

Specify an IEntity ID as the matching criteria

public Replace<T> MatchID(object ID)

Parameters

ID object

A unique IEntity ID

Returns

Replace<T>

MatchString(string)

Specify the matching criteria with a JSON string

public Replace<T> MatchString(string jsonString)

Parameters

jsonString string

{ 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

option Action<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

entity T

Returns

Replace<T>