Method ReplaceOne
ReplaceOne<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, TDocument, ReplaceOptions, CancellationToken)
Replaces a single document.
public static ReplaceOneResult ReplaceOne<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default)
Parameters
collectionIMongoCollection<TDocument>The collection.
filterExpression<Func<TDocument, bool>>The filter.
replacementTDocumentThe replacement.
optionsReplaceOptionsThe options.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- ReplaceOneResult
The result of the replacement.
Type Parameters
TDocumentThe type of the document.
ReplaceOne<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 ReplaceOneResult ReplaceOne<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default)
Parameters
collectionIMongoCollection<TDocument>The collection.
filterExpression<Func<TDocument, bool>>The filter.
replacementTDocumentThe replacement.
optionsUpdateOptionsThe options.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- ReplaceOneResult
The result of the replacement.
Type Parameters
TDocumentThe type of the document.
ReplaceOne<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, TDocument, ReplaceOptions, CancellationToken)
Replaces a single document.
public static ReplaceOneResult ReplaceOne<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default)
Parameters
collectionIMongoCollection<TDocument>The collection.
sessionIClientSessionHandleThe session.
filterExpression<Func<TDocument, bool>>The filter.
replacementTDocumentThe replacement.
optionsReplaceOptionsThe options.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- ReplaceOneResult
The result of the replacement.
Type Parameters
TDocumentThe type of the document.
ReplaceOne<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 ReplaceOneResult ReplaceOne<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default)
Parameters
collectionIMongoCollection<TDocument>The collection.
sessionIClientSessionHandleThe session.
filterExpression<Func<TDocument, bool>>The filter.
replacementTDocumentThe replacement.
optionsUpdateOptionsThe options.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- ReplaceOneResult
The result of the replacement.
Type Parameters
TDocumentThe type of the document.