Table of Contents

Method FindOneAndDelete

Namespace
MongoDB.Driver
Assembly
MongoDB.Driver.dll

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

Finds a single document and deletes it atomically.

public static TDocument FindOneAndDelete<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

TDocument

The deleted document if one was deleted.

Type Parameters

TDocument

The type of the document.

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

Finds a single document and deletes it atomically.

public static TDocument FindOneAndDelete<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

TDocument

The deleted document if one was deleted.

Type Parameters

TDocument

The type of the document.

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

Finds a single document and deletes it atomically.

public static TProjection FindOneAndDelete<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

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

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

Finds a single document and deletes it atomically.

public static TDocument FindOneAndDelete<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

TDocument

The deleted document if one was deleted.

Type Parameters

TDocument

The type of the document.

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

Finds a single document and deletes it atomically.

public static TDocument FindOneAndDelete<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

TDocument

The deleted document if one was deleted.

Type Parameters

TDocument

The type of the document.

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

Finds a single document and deletes it atomically.

public static TProjection FindOneAndDelete<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

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