Method FindOneAndUpdate
FindOneAndUpdate<TDocument>(IMongoCollection<TDocument>, FilterDefinition<TDocument>, UpdateDefinition<TDocument>, FindOneAndUpdateOptions<TDocument, TDocument>, CancellationToken)
Finds a single document and updates it atomically.
public static TDocument FindOneAndUpdate<TDocument>(this IMongoCollection<TDocument> collection, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TDocument> options = null, CancellationToken cancellationToken = default)
Parameters
collection
IMongoCollection<TDocument>The collection.
filter
FilterDefinition<TDocument>The filter.
update
UpdateDefinition<TDocument>The update.
options
FindOneAndUpdateOptions<TDocument, TDocument>The options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- TDocument
The returned document.
Type Parameters
TDocument
The type of the document.
FindOneAndUpdate<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, UpdateDefinition<TDocument>, FindOneAndUpdateOptions<TDocument>, CancellationToken)
Finds a single document and updates it atomically.
public static TDocument FindOneAndUpdate<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument> options = null, CancellationToken cancellationToken = default)
Parameters
collection
IMongoCollection<TDocument>The collection.
filter
Expression<Func<TDocument, bool>>The filter.
update
UpdateDefinition<TDocument>The update.
options
FindOneAndUpdateOptions<TDocument>The options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- TDocument
The returned document.
Type Parameters
TDocument
The type of the document.
FindOneAndUpdate<TDocument, TProjection>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, UpdateDefinition<TDocument>, FindOneAndUpdateOptions<TDocument, TProjection>, CancellationToken)
Finds a single document and updates it atomically.
public static TProjection FindOneAndUpdate<TDocument, TProjection>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default)
Parameters
collection
IMongoCollection<TDocument>The collection.
filter
Expression<Func<TDocument, bool>>The filter.
update
UpdateDefinition<TDocument>The update.
options
FindOneAndUpdateOptions<TDocument, TProjection>The options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- TProjection
The returned document.
Type Parameters
TDocument
The type of the document.
TProjection
The type of the projection (same as TDocument if there is no projection).
FindOneAndUpdate<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, FilterDefinition<TDocument>, UpdateDefinition<TDocument>, FindOneAndUpdateOptions<TDocument, TDocument>, CancellationToken)
Finds a single document and updates it atomically.
public static TDocument FindOneAndUpdate<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TDocument> options = null, CancellationToken cancellationToken = default)
Parameters
collection
IMongoCollection<TDocument>The collection.
session
IClientSessionHandleThe session.
filter
FilterDefinition<TDocument>The filter.
update
UpdateDefinition<TDocument>The update.
options
FindOneAndUpdateOptions<TDocument, TDocument>The options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- TDocument
The returned document.
Type Parameters
TDocument
The type of the document.
FindOneAndUpdate<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, UpdateDefinition<TDocument>, FindOneAndUpdateOptions<TDocument, TDocument>, CancellationToken)
Finds a single document and updates it atomically.
public static TDocument FindOneAndUpdate<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TDocument> 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
FindOneAndUpdateOptions<TDocument, TDocument>The options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- TDocument
The returned document.
Type Parameters
TDocument
The type of the document.
FindOneAndUpdate<TDocument, TProjection>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, UpdateDefinition<TDocument>, FindOneAndUpdateOptions<TDocument, TProjection>, CancellationToken)
Finds a single document and updates it atomically.
public static TProjection FindOneAndUpdate<TDocument, TProjection>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TProjection> 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
FindOneAndUpdateOptions<TDocument, TProjection>The options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- TProjection
The returned document.
Type Parameters
TDocument
The type of the document.
TProjection
The type of the projection (same as TDocument if there is no projection).