Method UpdateOneAsync
UpdateOneAsync<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, UpdateDefinition<TDocument>, UpdateOptions, CancellationToken)
Updates a single document.
public static Task<UpdateResult> UpdateOneAsync<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default)
Parameters
collection
IMongoCollection<TDocument>The collection.
filter
Expression<Func<TDocument, bool>>The filter.
update
UpdateDefinition<TDocument>The update.
options
UpdateOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<UpdateResult>
The result of the update operation.
Type Parameters
TDocument
The type of the document.
UpdateOneAsync<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, UpdateDefinition<TDocument>, UpdateOptions, CancellationToken)
Updates a single document.
public static Task<UpdateResult> UpdateOneAsync<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default)
Parameters
collection
IMongoCollection<TDocument>The collection.
session
IClientSessionHandleThe session.
filter
Expression<Func<TDocument, bool>>The filter.
update
UpdateDefinition<TDocument>The update.
options
UpdateOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<UpdateResult>
The result of the update operation.
Type Parameters
TDocument
The type of the document.