Table of Contents

Method FindOneAndUpdate

Namespace
MongoDB.Driver
Assembly
MongoDB.Driver.dll

FindOneAndUpdate<TProjection>(FilterDefinition<TDocument>, UpdateDefinition<TDocument>, FindOneAndUpdateOptions<TDocument, TProjection>, CancellationToken)

Finds a single document and updates it atomically.

public virtual TProjection FindOneAndUpdate<TProjection>(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default)

Parameters

filter FilterDefinition<TDocument>

The filter.

update UpdateDefinition<TDocument>

The update.

options FindOneAndUpdateOptions<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).

FindOneAndUpdate<TProjection>(IClientSessionHandle, FilterDefinition<TDocument>, UpdateDefinition<TDocument>, FindOneAndUpdateOptions<TDocument, TProjection>, CancellationToken)

Finds a single document and updates it atomically.

public virtual TProjection FindOneAndUpdate<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default)

Parameters

session IClientSessionHandle

The session.

filter FilterDefinition<TDocument>

The filter.

update UpdateDefinition<TDocument>

The update.

options FindOneAndUpdateOptions<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).