Method FindOneAndReplaceAsync
FindOneAndReplaceAsync<TProjection>(FilterDefinition<TDocument>, TDocument, FindOneAndReplaceOptions<TDocument, TProjection>, CancellationToken)
Finds a single document and replaces it atomically.
public abstract Task<TProjection> FindOneAndReplaceAsync<TProjection>(FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition<TDocument>The filter.
replacement
TDocumentThe replacement.
options
FindOneAndReplaceOptions<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).
FindOneAndReplaceAsync<TProjection>(IClientSessionHandle, FilterDefinition<TDocument>, TDocument, FindOneAndReplaceOptions<TDocument, TProjection>, CancellationToken)
Finds a single document and replaces it atomically.
public virtual Task<TProjection> FindOneAndReplaceAsync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
filter
FilterDefinition<TDocument>The filter.
replacement
TDocumentThe replacement.
options
FindOneAndReplaceOptions<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).