Table of Contents

Method FindOneAndReplace

Namespace
MongoDB.Driver
Assembly
MongoDB.Driver.dll

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

Finds a single document and replaces it atomically.

TProjection FindOneAndReplace<TProjection>(FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default)

Parameters

filter FilterDefinition<TDocument>

The filter.

replacement TDocument

The replacement.

options FindOneAndReplaceOptions<TDocument, TProjection>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

TProjection

The returned document.

Type Parameters

TProjection

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

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

Finds a single document and replaces it atomically.

TProjection FindOneAndReplace<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default)

Parameters

session IClientSessionHandle

The session.

filter FilterDefinition<TDocument>

The filter.

replacement TDocument

The replacement.

options FindOneAndReplaceOptions<TDocument, TProjection>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

TProjection

The returned document.

Type Parameters

TProjection

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