Method FindOneAndUpdateAsync
FindOneAndUpdateAsync<TProjection>(FilterDefinition<TDocument>, UpdateDefinition<TDocument>, FindOneAndUpdateOptions<TDocument, TProjection>, CancellationToken)
Finds a single document and updates it atomically.
Task<TProjection> FindOneAndUpdateAsync<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
CancellationTokenThe cancellation token.
Returns
- Task<TProjection>
The returned document.
Type Parameters
TProjection
The type of the projection (same as TDocument if there is no projection).
FindOneAndUpdateAsync<TProjection>(IClientSessionHandle, FilterDefinition<TDocument>, UpdateDefinition<TDocument>, FindOneAndUpdateOptions<TDocument, TProjection>, CancellationToken)
Finds a single document and updates it atomically.
Task<TProjection> FindOneAndUpdateAsync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
filter
FilterDefinition<TDocument>The filter.
update
UpdateDefinition<TDocument>The update.
options
FindOneAndUpdateOptions<TDocument, TProjection>The options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<TProjection>
The returned document.
Type Parameters
TProjection
The type of the projection (same as TDocument if there is no projection).