Method FindOneAndUpdate
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
CancellationTokenThe 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
IClientSessionHandleThe session.
filter
FilterDefinition<TDocument>The filter.
update
UpdateDefinition<TDocument>The update.
options
FindOneAndUpdateOptions<TDocument, TProjection>The options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- TProjection
The returned document.
Type Parameters
TProjection
The type of the projection (same as TDocument if there is no projection).