Table of Contents

Method FindOneAndUpdateAsync

Namespace
MongoDB.Driver
Assembly
MongoDB.Driver.dll

FindOneAndUpdateAsync<TDocument>(IMongoCollection<TDocument>, FilterDefinition<TDocument>, UpdateDefinition<TDocument>, FindOneAndUpdateOptions<TDocument, TDocument>, CancellationToken)

Finds a single document and updates it atomically.

public static Task<TDocument> FindOneAndUpdateAsync<TDocument>(this IMongoCollection<TDocument> collection, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TDocument> options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

filter FilterDefinition<TDocument>

The filter.

update UpdateDefinition<TDocument>

The update.

options FindOneAndUpdateOptions<TDocument, TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TDocument>

The returned document.

Type Parameters

TDocument

The type of the document.

FindOneAndUpdateAsync<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, UpdateDefinition<TDocument>, FindOneAndUpdateOptions<TDocument>, CancellationToken)

Finds a single document and updates it atomically.

public static Task<TDocument> FindOneAndUpdateAsync<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument> options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

update UpdateDefinition<TDocument>

The update.

options FindOneAndUpdateOptions<TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TDocument>

The returned document.

Type Parameters

TDocument

The type of the document.

FindOneAndUpdateAsync<TDocument, TProjection>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, UpdateDefinition<TDocument>, FindOneAndUpdateOptions<TDocument, TProjection>, CancellationToken)

Finds a single document and updates it atomically.

public static Task<TProjection> FindOneAndUpdateAsync<TDocument, TProjection>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

update UpdateDefinition<TDocument>

The update.

options FindOneAndUpdateOptions<TDocument, TProjection>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<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).

FindOneAndUpdateAsync<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, FilterDefinition<TDocument>, UpdateDefinition<TDocument>, FindOneAndUpdateOptions<TDocument, TDocument>, CancellationToken)

Finds a single document and updates it atomically.

public static Task<TDocument> FindOneAndUpdateAsync<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TDocument> options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

filter FilterDefinition<TDocument>

The filter.

update UpdateDefinition<TDocument>

The update.

options FindOneAndUpdateOptions<TDocument, TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TDocument>

The returned document.

Type Parameters

TDocument

The type of the document.

FindOneAndUpdateAsync<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, UpdateDefinition<TDocument>, FindOneAndUpdateOptions<TDocument, TDocument>, CancellationToken)

Finds a single document and updates it atomically.

public static Task<TDocument> FindOneAndUpdateAsync<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TDocument> options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

update UpdateDefinition<TDocument>

The update.

options FindOneAndUpdateOptions<TDocument, TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TDocument>

The returned document.

Type Parameters

TDocument

The type of the document.

FindOneAndUpdateAsync<TDocument, TProjection>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, UpdateDefinition<TDocument>, FindOneAndUpdateOptions<TDocument, TProjection>, CancellationToken)

Finds a single document and updates it atomically.

public static Task<TProjection> FindOneAndUpdateAsync<TDocument, TProjection>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

update UpdateDefinition<TDocument>

The update.

options FindOneAndUpdateOptions<TDocument, TProjection>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<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).