Table of Contents

Method FindOneAndDeleteAsync

Namespace
MongoDB.Driver
Assembly
MongoDB.Driver.dll

FindOneAndDeleteAsync<TDocument>(IMongoCollection<TDocument>, FilterDefinition<TDocument>, FindOneAndDeleteOptions<TDocument, TDocument>, CancellationToken)

Finds a single document and deletes it atomically.

public static Task<TDocument> FindOneAndDeleteAsync<TDocument>(this IMongoCollection<TDocument> collection, FilterDefinition<TDocument> filter, FindOneAndDeleteOptions<TDocument, TDocument> options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

filter FilterDefinition<TDocument>

The filter.

options FindOneAndDeleteOptions<TDocument, TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TDocument>

The deleted document if one was deleted.

Type Parameters

TDocument

The type of the document.

FindOneAndDeleteAsync<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, FindOneAndDeleteOptions<TDocument>, CancellationToken)

Finds a single document and deletes it atomically.

public static Task<TDocument> FindOneAndDeleteAsync<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, FindOneAndDeleteOptions<TDocument> options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

options FindOneAndDeleteOptions<TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TDocument>

The deleted document if one was deleted.

Type Parameters

TDocument

The type of the document.

FindOneAndDeleteAsync<TDocument, TProjection>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, FindOneAndDeleteOptions<TDocument, TProjection>, CancellationToken)

Finds a single document and deletes it atomically.

public static Task<TProjection> FindOneAndDeleteAsync<TDocument, TProjection>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, FindOneAndDeleteOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

options FindOneAndDeleteOptions<TDocument, TProjection>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<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).

FindOneAndDeleteAsync<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, FilterDefinition<TDocument>, FindOneAndDeleteOptions<TDocument, TDocument>, CancellationToken)

Finds a single document and deletes it atomically.

public static Task<TDocument> FindOneAndDeleteAsync<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, FilterDefinition<TDocument> filter, FindOneAndDeleteOptions<TDocument, TDocument> options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

filter FilterDefinition<TDocument>

The filter.

options FindOneAndDeleteOptions<TDocument, TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TDocument>

The deleted document if one was deleted.

Type Parameters

TDocument

The type of the document.

FindOneAndDeleteAsync<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, FindOneAndDeleteOptions<TDocument, TDocument>, CancellationToken)

Finds a single document and deletes it atomically.

public static Task<TDocument> FindOneAndDeleteAsync<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, FindOneAndDeleteOptions<TDocument, TDocument> options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

options FindOneAndDeleteOptions<TDocument, TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TDocument>

The deleted document if one was deleted.

Type Parameters

TDocument

The type of the document.

FindOneAndDeleteAsync<TDocument, TProjection>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, FindOneAndDeleteOptions<TDocument, TProjection>, CancellationToken)

Finds a single document and deletes it atomically.

public static Task<TProjection> FindOneAndDeleteAsync<TDocument, TProjection>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, FindOneAndDeleteOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

options FindOneAndDeleteOptions<TDocument, TProjection>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<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).