Method UpdateOne
UpdateOne<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, UpdateDefinition<TDocument>, UpdateOptions, CancellationToken)
Updates a single document.
public static UpdateResult UpdateOne<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default)
Parameters
collectionIMongoCollection<TDocument>The collection.
filterExpression<Func<TDocument, bool>>The filter.
updateUpdateDefinition<TDocument>The update.
optionsUpdateOptionsThe options.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- UpdateResult
The result of the update operation.
Type Parameters
TDocumentThe type of the document.
UpdateOne<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, UpdateDefinition<TDocument>, UpdateOptions, CancellationToken)
Updates a single document.
public static UpdateResult UpdateOne<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default)
Parameters
collectionIMongoCollection<TDocument>The collection.
sessionIClientSessionHandleThe session.
filterExpression<Func<TDocument, bool>>The filter.
updateUpdateDefinition<TDocument>The update.
optionsUpdateOptionsThe options.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- UpdateResult
The result of the update operation.
Type Parameters
TDocumentThe type of the document.