Method FindOneAndUpdate

| MongoDB CSharp Driver API Reference (original) (raw)

Namespace

MongoDB.Driver

Assembly

MongoDB.Driver.dll

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

Finds a single document and updates it atomically.

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

Parameters

collection IMongoCollection

The collection.

filter FilterDefinition

The filter.

update UpdateDefinition

The update.

options FindOneAndUpdateOptions<TDocument, TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

TDocument

The returned document.

Type Parameters

TDocument

The type of the document.

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

Finds a single document and updates it atomically.

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

Parameters

collection IMongoCollection

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

update UpdateDefinition

The update.

options FindOneAndUpdateOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

TDocument

The returned document.

Type Parameters

TDocument

The type of the document.

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

Finds a single document and updates it atomically.

public static TProjection FindOneAndUpdate<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

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

update UpdateDefinition

The update.

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

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

Finds a single document and updates it atomically.

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

Parameters

collection IMongoCollection

The collection.

session IClientSessionHandle

The session.

filter FilterDefinition

The filter.

update UpdateDefinition

The update.

options FindOneAndUpdateOptions<TDocument, TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

TDocument

The returned document.

Type Parameters

TDocument

The type of the document.

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

Finds a single document and updates it atomically.

public static TDocument FindOneAndUpdate<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

The collection.

session IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

update UpdateDefinition

The update.

options FindOneAndUpdateOptions<TDocument, TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

TDocument

The returned document.

Type Parameters

TDocument

The type of the document.

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

Finds a single document and updates it atomically.

public static TProjection FindOneAndUpdate<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

The collection.

session IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

update UpdateDefinition

The update.

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