Method ReplaceOneAsync
ReplaceOneAsync<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, TDocument, ReplaceOptions, CancellationToken)
Replaces a single document.
public static Task<ReplaceOneResult> ReplaceOneAsync<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default)
Parameters
collection
IMongoCollection<TDocument>The collection.
filter
Expression<Func<TDocument, bool>>The filter.
replacement
TDocumentThe replacement.
options
ReplaceOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<ReplaceOneResult>
The result of the replacement.
Type Parameters
TDocument
The type of the document.
ReplaceOneAsync<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, TDocument, UpdateOptions, CancellationToken)
Replaces a single document.
[Obsolete("Use the overload that takes a ReplaceOptions instead of an UpdateOptions.")]
public static Task<ReplaceOneResult> ReplaceOneAsync<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default)
Parameters
collection
IMongoCollection<TDocument>The collection.
filter
Expression<Func<TDocument, bool>>The filter.
replacement
TDocumentThe replacement.
options
UpdateOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<ReplaceOneResult>
The result of the replacement.
Type Parameters
TDocument
The type of the document.
ReplaceOneAsync<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, TDocument, ReplaceOptions, CancellationToken)
Replaces a single document.
public static Task<ReplaceOneResult> ReplaceOneAsync<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default)
Parameters
collection
IMongoCollection<TDocument>The collection.
session
IClientSessionHandleThe session.
filter
Expression<Func<TDocument, bool>>The filter.
replacement
TDocumentThe replacement.
options
ReplaceOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<ReplaceOneResult>
The result of the replacement.
Type Parameters
TDocument
The type of the document.
ReplaceOneAsync<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, TDocument, UpdateOptions, CancellationToken)
Replaces a single document.
[Obsolete("Use the overload that takes a ReplaceOptions instead of an UpdateOptions.")]
public static Task<ReplaceOneResult> ReplaceOneAsync<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default)
Parameters
collection
IMongoCollection<TDocument>The collection.
session
IClientSessionHandleThe session.
filter
Expression<Func<TDocument, bool>>The filter.
replacement
TDocumentThe replacement.
options
UpdateOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<ReplaceOneResult>
The result of the replacement.
Type Parameters
TDocument
The type of the document.