Table of Contents

Method FindOneAndReplace

Namespace
MongoDB.Driver
Assembly
MongoDB.Driver.dll

FindOneAndReplace<TDocument>(IMongoCollection<TDocument>, FilterDefinition<TDocument>, TDocument, FindOneAndReplaceOptions<TDocument, TDocument>, CancellationToken)

Finds a single document and replaces it atomically.

public static TDocument FindOneAndReplace<TDocument>(this IMongoCollection<TDocument> collection, FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TDocument> options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

filter FilterDefinition<TDocument>

The filter.

replacement TDocument

The replacement.

options FindOneAndReplaceOptions<TDocument, TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

TDocument

The returned document.

Type Parameters

TDocument

The type of the document.

FindOneAndReplace<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, TDocument, FindOneAndReplaceOptions<TDocument>, CancellationToken)

Finds a single document and replaces it atomically.

public static TDocument FindOneAndReplace<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument> options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

replacement TDocument

The replacement.

options FindOneAndReplaceOptions<TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

TDocument

The returned document.

Type Parameters

TDocument

The type of the document.

FindOneAndReplace<TDocument, TProjection>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, TDocument, FindOneAndReplaceOptions<TDocument, TProjection>, CancellationToken)

Finds a single document and replaces it atomically.

public static TProjection FindOneAndReplace<TDocument, TProjection>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

replacement TDocument

The replacement.

options FindOneAndReplaceOptions<TDocument, TProjection>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

TProjection

The returned document.

Type Parameters

TDocument

The type of the document.

TProjection

The type of the projection (same as TDocument if there is no projection).

FindOneAndReplace<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, FilterDefinition<TDocument>, TDocument, FindOneAndReplaceOptions<TDocument, TDocument>, CancellationToken)

Finds a single document and replaces it atomically.

public static TDocument FindOneAndReplace<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TDocument> options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

filter FilterDefinition<TDocument>

The filter.

replacement TDocument

The replacement.

options FindOneAndReplaceOptions<TDocument, TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

TDocument

The returned document.

Type Parameters

TDocument

The type of the document.

FindOneAndReplace<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, TDocument, FindOneAndReplaceOptions<TDocument, TDocument>, CancellationToken)

Finds a single document and replaces it atomically.

public static TDocument FindOneAndReplace<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TDocument> options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

replacement TDocument

The replacement.

options FindOneAndReplaceOptions<TDocument, TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

TDocument

The returned document.

Type Parameters

TDocument

The type of the document.

FindOneAndReplace<TDocument, TProjection>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, TDocument, FindOneAndReplaceOptions<TDocument, TProjection>, CancellationToken)

Finds a single document and replaces it atomically.

public static TProjection FindOneAndReplace<TDocument, TProjection>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

replacement TDocument

The replacement.

options FindOneAndReplaceOptions<TDocument, TProjection>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

TProjection

The returned document.

Type Parameters

TDocument

The type of the document.

TProjection

The type of the projection (same as TDocument if there is no projection).