Method FindOneAndReplaceAsync
FindOneAndReplaceAsync<TDocument>(IMongoCollection<TDocument>, FilterDefinition<TDocument>, TDocument, FindOneAndReplaceOptions<TDocument, TDocument>, CancellationToken)
Finds a single document and replaces it atomically.
public static Task<TDocument> FindOneAndReplaceAsync<TDocument>(this IMongoCollection<TDocument> collection, FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TDocument> options = null, CancellationToken cancellationToken = default)
Parameters
collectionIMongoCollection<TDocument>The collection.
filterFilterDefinition<TDocument>The filter.
replacementTDocumentThe replacement.
optionsFindOneAndReplaceOptions<TDocument, TDocument>The options.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<TDocument>
The returned document.
Type Parameters
TDocumentThe type of the document.
FindOneAndReplaceAsync<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, TDocument, FindOneAndReplaceOptions<TDocument, TDocument>, CancellationToken)
Finds a single document and replaces it atomically.
public static Task<TDocument> FindOneAndReplaceAsync<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TDocument> options = null, CancellationToken cancellationToken = default)
Parameters
collectionIMongoCollection<TDocument>The collection.
filterExpression<Func<TDocument, bool>>The filter.
replacementTDocumentThe replacement.
optionsFindOneAndReplaceOptions<TDocument, TDocument>The options.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<TDocument>
The returned document.
Type Parameters
TDocumentThe type of the document.
FindOneAndReplaceAsync<TDocument, TProjection>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, TDocument, FindOneAndReplaceOptions<TDocument, TProjection>, CancellationToken)
Finds a single document and replaces it atomically.
public static Task<TProjection> FindOneAndReplaceAsync<TDocument, TProjection>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default)
Parameters
collectionIMongoCollection<TDocument>The collection.
filterExpression<Func<TDocument, bool>>The filter.
replacementTDocumentThe replacement.
optionsFindOneAndReplaceOptions<TDocument, TProjection>The options.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<TProjection>
The returned document.
Type Parameters
TDocumentThe type of the document.
TProjectionThe type of the projection (same as TDocument if there is no projection).
FindOneAndReplaceAsync<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, FilterDefinition<TDocument>, TDocument, FindOneAndReplaceOptions<TDocument, TDocument>, CancellationToken)
Finds a single document and replaces it atomically.
public static Task<TDocument> FindOneAndReplaceAsync<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TDocument> options = null, CancellationToken cancellationToken = default)
Parameters
collectionIMongoCollection<TDocument>The collection.
sessionIClientSessionHandleThe session.
filterFilterDefinition<TDocument>The filter.
replacementTDocumentThe replacement.
optionsFindOneAndReplaceOptions<TDocument, TDocument>The options.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<TDocument>
The returned document.
Type Parameters
TDocumentThe type of the document.
FindOneAndReplaceAsync<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, IClientSessionHandle, TDocument, FindOneAndReplaceOptions<TDocument, TDocument>, CancellationToken)
Finds a single document and replaces it atomically.
public static Task<TDocument> FindOneAndReplaceAsync<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, IClientSessionHandle session, TDocument replacement, FindOneAndReplaceOptions<TDocument, TDocument> options = null, CancellationToken cancellationToken = default)
Parameters
collectionIMongoCollection<TDocument>The collection.
filterExpression<Func<TDocument, bool>>The filter.
sessionIClientSessionHandleThe session.
replacementTDocumentThe replacement.
optionsFindOneAndReplaceOptions<TDocument, TDocument>The options.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<TDocument>
The returned document.
Type Parameters
TDocumentThe type of the document.
FindOneAndReplaceAsync<TDocument, TProjection>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, TDocument, FindOneAndReplaceOptions<TDocument, TProjection>, CancellationToken)
Finds a single document and replaces it atomically.
public static Task<TProjection> FindOneAndReplaceAsync<TDocument, TProjection>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default)
Parameters
collectionIMongoCollection<TDocument>The collection.
sessionIClientSessionHandleThe session.
filterExpression<Func<TDocument, bool>>The filter.
replacementTDocumentThe replacement.
optionsFindOneAndReplaceOptions<TDocument, TProjection>The options.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<TProjection>
The returned document.
Type Parameters
TDocumentThe type of the document.
TProjectionThe type of the projection (same as TDocument if there is no projection).