Table of Contents

Class IMongoCollectionExtensions

Namespace
MongoDB.Driver
Assembly
MongoDB.Driver.dll

Extension methods for IMongoCollection<TDocument>.

public static class IMongoCollectionExtensions
Inheritance
IMongoCollectionExtensions
Inherited Members

Methods

Aggregate<TDocument>(IMongoCollection<TDocument>, AggregateOptions)

Begins a fluent aggregation interface.

public static IAggregateFluent<TDocument> Aggregate<TDocument>(this IMongoCollection<TDocument> collection, AggregateOptions options = null)

Parameters

collection IMongoCollection<TDocument>

The collection.

options AggregateOptions

The options.

Returns

IAggregateFluent<TDocument>

A fluent aggregate interface.

Type Parameters

TDocument

The type of the document.

Aggregate<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, AggregateOptions)

Begins a fluent aggregation interface.

public static IAggregateFluent<TDocument> Aggregate<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, AggregateOptions options = null)

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

options AggregateOptions

The options.

Returns

IAggregateFluent<TDocument>

A fluent aggregate interface.

Type Parameters

TDocument

The type of the document.

AsQueryable<TDocument>(IMongoCollection<TDocument>, AggregateOptions)

Creates a queryable source of documents.

public static IMongoQueryable<TDocument> AsQueryable<TDocument>(this IMongoCollection<TDocument> collection, AggregateOptions aggregateOptions = null)

Parameters

collection IMongoCollection<TDocument>

The collection.

aggregateOptions AggregateOptions

The aggregate options

Returns

IMongoQueryable<TDocument>

A queryable source of documents.

Type Parameters

TDocument

The type of the document.

AsQueryable<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, AggregateOptions)

Creates a queryable source of documents.

public static IMongoQueryable<TDocument> AsQueryable<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, AggregateOptions aggregateOptions = null)

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

aggregateOptions AggregateOptions

The aggregate options

Returns

IMongoQueryable<TDocument>

A queryable source of documents.

Type Parameters

TDocument

The type of the document.

CountAsync<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, CountOptions, CancellationToken)

Counts the number of documents in the collection.

[Obsolete("Use CountDocumentsAsync or EstimatedDocumentCountAsync instead.")]
public static Task<long> CountAsync<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, CountOptions options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

options CountOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<long>

The number of documents in the collection.

Type Parameters

TDocument

The type of the document.

CountAsync<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, CountOptions, CancellationToken)

Counts the number of documents in the collection.

[Obsolete("Use CountDocumentsAsync or EstimatedDocumentCountAsync instead.")]
public static Task<long> CountAsync<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, CountOptions options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

options CountOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<long>

The number of documents in the collection.

Type Parameters

TDocument

The type of the document.

CountDocumentsAsync<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, CountOptions, CancellationToken)

Counts the number of documents in the collection. For a fast estimate of the total documents in a collection see EstimatedDocumentCountAsync(EstimatedDocumentCountOptions, CancellationToken).

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

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

options CountOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<long>

The number of documents in the collection.

Type Parameters

TDocument

The type of the document.

CountDocumentsAsync<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, CountOptions, CancellationToken)

Counts the number of documents in the collection. For a fast estimate of the total documents in a collection see EstimatedDocumentCountAsync(EstimatedDocumentCountOptions, CancellationToken).

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

Parameters

collection IMongoCollection<TDocument>

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

options CountOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<long>

The number of documents in the collection.

Type Parameters

TDocument

The type of the document.

CountDocuments<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, CountOptions, CancellationToken)

Counts the number of documents in the collection. For a fast estimate of the total documents in a collection see EstimatedDocumentCount(EstimatedDocumentCountOptions, CancellationToken).

public static long CountDocuments<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, CountOptions options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

options CountOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

long

The number of documents in the collection.

Type Parameters

TDocument

The type of the document.

CountDocuments<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, CountOptions, CancellationToken)

Counts the number of documents in the collection. For a fast estimate of the total documents in a collection see EstimatedDocumentCount(EstimatedDocumentCountOptions, CancellationToken).

public static long CountDocuments<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, CountOptions options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

options CountOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

long

The number of documents in the collection.

Type Parameters

TDocument

The type of the document.

Count<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, CountOptions, CancellationToken)

Counts the number of documents in the collection.

[Obsolete("Use CountDocuments or EstimatedDocumentCount instead.")]
public static long Count<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, CountOptions options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

options CountOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

long

The number of documents in the collection.

Type Parameters

TDocument

The type of the document.

Count<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, CountOptions, CancellationToken)

Counts the number of documents in the collection.

[Obsolete("Use CountDocuments or EstimatedDocumentCount instead.")]
public static long Count<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, CountOptions options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

options CountOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

long

The number of documents in the collection.

Type Parameters

TDocument

The type of the document.

DeleteManyAsync<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, DeleteOptions, CancellationToken)

Deletes multiple documents.

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

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

options DeleteOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<DeleteResult>

The result of the delete operation.

Type Parameters

TDocument

The type of the document.

DeleteManyAsync<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, DeleteOptions, CancellationToken)

Deletes multiple documents.

public static Task<DeleteResult> DeleteManyAsync<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, DeleteOptions options, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

options DeleteOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<DeleteResult>

The result of the delete operation.

Type Parameters

TDocument

The type of the document.

DeleteManyAsync<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, CancellationToken)

Deletes multiple documents.

public static Task<DeleteResult> DeleteManyAsync<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<DeleteResult>

The result of the delete operation.

Type Parameters

TDocument

The type of the document.

DeleteMany<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, DeleteOptions, CancellationToken)

Deletes multiple documents.

public static DeleteResult DeleteMany<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, DeleteOptions options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

options DeleteOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

DeleteResult

The result of the delete operation.

Type Parameters

TDocument

The type of the document.

DeleteMany<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, DeleteOptions, CancellationToken)

Deletes multiple documents.

public static DeleteResult DeleteMany<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, DeleteOptions options, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

options DeleteOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

DeleteResult

The result of the delete operation.

Type Parameters

TDocument

The type of the document.

DeleteMany<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, CancellationToken)

Deletes multiple documents.

public static DeleteResult DeleteMany<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

cancellationToken CancellationToken

The cancellation token.

Returns

DeleteResult

The result of the delete operation.

Type Parameters

TDocument

The type of the document.

DeleteOneAsync<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, DeleteOptions, CancellationToken)

Deletes a single document.

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

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

options DeleteOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<DeleteResult>

The result of the delete operation.

Type Parameters

TDocument

The type of the document.

DeleteOneAsync<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, DeleteOptions, CancellationToken)

Deletes a single document.

public static Task<DeleteResult> DeleteOneAsync<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, DeleteOptions options, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

options DeleteOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<DeleteResult>

The result of the delete operation.

Type Parameters

TDocument

The type of the document.

DeleteOneAsync<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, CancellationToken)

Deletes a single document.

public static Task<DeleteResult> DeleteOneAsync<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<DeleteResult>

The result of the delete operation.

Type Parameters

TDocument

The type of the document.

DeleteOne<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, DeleteOptions, CancellationToken)

Deletes a single document.

public static DeleteResult DeleteOne<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, DeleteOptions options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

options DeleteOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

DeleteResult

The result of the delete operation.

Type Parameters

TDocument

The type of the document.

DeleteOne<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, DeleteOptions, CancellationToken)

Deletes a single document.

public static DeleteResult DeleteOne<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, DeleteOptions options, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

options DeleteOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

DeleteResult

The result of the delete operation.

Type Parameters

TDocument

The type of the document.

DeleteOne<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, CancellationToken)

Deletes a single document.

public static DeleteResult DeleteOne<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

cancellationToken CancellationToken

The cancellation token.

Returns

DeleteResult

The result of the delete operation.

Type Parameters

TDocument

The type of the document.

DistinctAsync<TDocument, TField>(IMongoCollection<TDocument>, FieldDefinition<TDocument, TField>, Expression<Func<TDocument, bool>>, DistinctOptions, CancellationToken)

Gets the distinct values for a specified field.

public static Task<IAsyncCursor<TField>> DistinctAsync<TDocument, TField>(this IMongoCollection<TDocument> collection, FieldDefinition<TDocument, TField> field, Expression<Func<TDocument, bool>> filter, DistinctOptions options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

field FieldDefinition<TDocument, TField>

The field.

filter Expression<Func<TDocument, bool>>

The filter.

options DistinctOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<IAsyncCursor<TField>>

The distinct values for the specified field.

Type Parameters

TDocument

The type of the document.

TField

The type of the result.

DistinctAsync<TDocument, TField>(IMongoCollection<TDocument>, IClientSessionHandle, FieldDefinition<TDocument, TField>, Expression<Func<TDocument, bool>>, DistinctOptions, CancellationToken)

Gets the distinct values for a specified field.

public static Task<IAsyncCursor<TField>> DistinctAsync<TDocument, TField>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, FieldDefinition<TDocument, TField> field, Expression<Func<TDocument, bool>> filter, DistinctOptions options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

field FieldDefinition<TDocument, TField>

The field.

filter Expression<Func<TDocument, bool>>

The filter.

options DistinctOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<IAsyncCursor<TField>>

The distinct values for the specified field.

Type Parameters

TDocument

The type of the document.

TField

The type of the result.

DistinctAsync<TDocument, TField>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, TField>>, FilterDefinition<TDocument>, DistinctOptions, CancellationToken)

Gets the distinct values for a specified field.

public static Task<IAsyncCursor<TField>> DistinctAsync<TDocument, TField>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, Expression<Func<TDocument, TField>> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

field Expression<Func<TDocument, TField>>

The field.

filter FilterDefinition<TDocument>

The filter.

options DistinctOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<IAsyncCursor<TField>>

The distinct values for the specified field.

Type Parameters

TDocument

The type of the document.

TField

The type of the result.

DistinctAsync<TDocument, TField>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, TField>>, Expression<Func<TDocument, bool>>, DistinctOptions, CancellationToken)

Gets the distinct values for a specified field.

public static Task<IAsyncCursor<TField>> DistinctAsync<TDocument, TField>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, Expression<Func<TDocument, TField>> field, Expression<Func<TDocument, bool>> filter, DistinctOptions options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

field Expression<Func<TDocument, TField>>

The field.

filter Expression<Func<TDocument, bool>>

The filter.

options DistinctOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<IAsyncCursor<TField>>

The distinct values for the specified field.

Type Parameters

TDocument

The type of the document.

TField

The type of the result.

DistinctAsync<TDocument, TField>(IMongoCollection<TDocument>, Expression<Func<TDocument, TField>>, FilterDefinition<TDocument>, DistinctOptions, CancellationToken)

Gets the distinct values for a specified field.

public static Task<IAsyncCursor<TField>> DistinctAsync<TDocument, TField>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, TField>> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

field Expression<Func<TDocument, TField>>

The field.

filter FilterDefinition<TDocument>

The filter.

options DistinctOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<IAsyncCursor<TField>>

The distinct values for the specified field.

Type Parameters

TDocument

The type of the document.

TField

The type of the result.

DistinctAsync<TDocument, TField>(IMongoCollection<TDocument>, Expression<Func<TDocument, TField>>, Expression<Func<TDocument, bool>>, DistinctOptions, CancellationToken)

Gets the distinct values for a specified field.

public static Task<IAsyncCursor<TField>> DistinctAsync<TDocument, TField>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, TField>> field, Expression<Func<TDocument, bool>> filter, DistinctOptions options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

field Expression<Func<TDocument, TField>>

The field.

filter Expression<Func<TDocument, bool>>

The filter.

options DistinctOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<IAsyncCursor<TField>>

The distinct values for the specified field.

Type Parameters

TDocument

The type of the document.

TField

The type of the result.

Distinct<TDocument, TField>(IMongoCollection<TDocument>, FieldDefinition<TDocument, TField>, Expression<Func<TDocument, bool>>, DistinctOptions, CancellationToken)

Gets the distinct values for a specified field.

public static IAsyncCursor<TField> Distinct<TDocument, TField>(this IMongoCollection<TDocument> collection, FieldDefinition<TDocument, TField> field, Expression<Func<TDocument, bool>> filter, DistinctOptions options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

field FieldDefinition<TDocument, TField>

The field.

filter Expression<Func<TDocument, bool>>

The filter.

options DistinctOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

IAsyncCursor<TField>

The distinct values for the specified field.

Type Parameters

TDocument

The type of the document.

TField

The type of the result.

Distinct<TDocument, TField>(IMongoCollection<TDocument>, IClientSessionHandle, FieldDefinition<TDocument, TField>, Expression<Func<TDocument, bool>>, DistinctOptions, CancellationToken)

Gets the distinct values for a specified field.

public static IAsyncCursor<TField> Distinct<TDocument, TField>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, FieldDefinition<TDocument, TField> field, Expression<Func<TDocument, bool>> filter, DistinctOptions options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

field FieldDefinition<TDocument, TField>

The field.

filter Expression<Func<TDocument, bool>>

The filter.

options DistinctOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

IAsyncCursor<TField>

The distinct values for the specified field.

Type Parameters

TDocument

The type of the document.

TField

The type of the result.

Distinct<TDocument, TField>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, TField>>, FilterDefinition<TDocument>, DistinctOptions, CancellationToken)

Gets the distinct values for a specified field.

public static IAsyncCursor<TField> Distinct<TDocument, TField>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, Expression<Func<TDocument, TField>> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

field Expression<Func<TDocument, TField>>

The field.

filter FilterDefinition<TDocument>

The filter.

options DistinctOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

IAsyncCursor<TField>

The distinct values for the specified field.

Type Parameters

TDocument

The type of the document.

TField

The type of the result.

Distinct<TDocument, TField>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, TField>>, Expression<Func<TDocument, bool>>, DistinctOptions, CancellationToken)

Gets the distinct values for a specified field.

public static IAsyncCursor<TField> Distinct<TDocument, TField>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, Expression<Func<TDocument, TField>> field, Expression<Func<TDocument, bool>> filter, DistinctOptions options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

field Expression<Func<TDocument, TField>>

The field.

filter Expression<Func<TDocument, bool>>

The filter.

options DistinctOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

IAsyncCursor<TField>

The distinct values for the specified field.

Type Parameters

TDocument

The type of the document.

TField

The type of the result.

Distinct<TDocument, TField>(IMongoCollection<TDocument>, Expression<Func<TDocument, TField>>, FilterDefinition<TDocument>, DistinctOptions, CancellationToken)

Gets the distinct values for a specified field.

public static IAsyncCursor<TField> Distinct<TDocument, TField>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, TField>> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

field Expression<Func<TDocument, TField>>

The field.

filter FilterDefinition<TDocument>

The filter.

options DistinctOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

IAsyncCursor<TField>

The distinct values for the specified field.

Type Parameters

TDocument

The type of the document.

TField

The type of the result.

Distinct<TDocument, TField>(IMongoCollection<TDocument>, Expression<Func<TDocument, TField>>, Expression<Func<TDocument, bool>>, DistinctOptions, CancellationToken)

Gets the distinct values for a specified field.

public static IAsyncCursor<TField> Distinct<TDocument, TField>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, TField>> field, Expression<Func<TDocument, bool>> filter, DistinctOptions options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

field Expression<Func<TDocument, TField>>

The field.

filter Expression<Func<TDocument, bool>>

The filter.

options DistinctOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

IAsyncCursor<TField>

The distinct values for the specified field.

Type Parameters

TDocument

The type of the document.

TField

The type of the result.

FindAsync<TDocument>(IMongoCollection<TDocument>, FilterDefinition<TDocument>, FindOptions<TDocument, TDocument>, CancellationToken)

Finds the documents matching the filter.

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

Parameters

collection IMongoCollection<TDocument>

The collection.

filter FilterDefinition<TDocument>

The filter.

options FindOptions<TDocument, TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<IAsyncCursor<TDocument>>

A Task whose result is a cursor.

Type Parameters

TDocument

The type of the document.

FindAsync<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, FilterDefinition<TDocument>, FindOptions<TDocument, TDocument>, CancellationToken)

Finds the documents matching the filter.

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

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

filter FilterDefinition<TDocument>

The filter.

options FindOptions<TDocument, TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<IAsyncCursor<TDocument>>

A Task whose result is a cursor.

Type Parameters

TDocument

The type of the document.

FindAsync<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, FindOptions<TDocument, TDocument>, CancellationToken)

Finds the documents matching the filter.

public static Task<IAsyncCursor<TDocument>> FindAsync<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, FindOptions<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 FindOptions<TDocument, TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<IAsyncCursor<TDocument>>

A Task whose result is a cursor.

Type Parameters

TDocument

The type of the document.

FindAsync<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, FindOptions<TDocument, TDocument>, CancellationToken)

Finds the documents matching the filter.

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

Parameters

collection IMongoCollection<TDocument>

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

options FindOptions<TDocument, TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<IAsyncCursor<TDocument>>

A Task whose result is a cursor.

Type Parameters

TDocument

The type of the document.

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>, 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>(IMongoCollection<TDocument>, 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, Expression<Func<TDocument, bool>> filter, FindOneAndDeleteOptions<TDocument, TDocument> options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

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

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

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>, 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>(IMongoCollection<TDocument>, 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, Expression<Func<TDocument, bool>> filter, FindOneAndDeleteOptions<TDocument, TDocument> options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

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

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

FindOneAndReplaceAsync<TDocument>(IMongoCollection<TDocument>, FilterDefinition<TDocument>, TDocument, FindOneAndReplaceOptions<TDocument, TDocument>, CancellationToken)

Finds a single document and replaces it atomically.

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

Parameters

collection IMongoCollection<TDocument>

The collection.

filter FilterDefinition<TDocument>

The filter.

replacement TDocument

The replacement.

options FindOneAndReplaceOptions<TDocument, TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TDocument>

The returned document.

Type Parameters

TDocument

The type of the document.

FindOneAndReplaceAsync<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, FilterDefinition<TDocument>, TDocument, FindOneAndReplaceOptions<TDocument, TDocument>, CancellationToken)

Finds a single document and replaces it atomically.

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

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

filter FilterDefinition<TDocument>

The filter.

replacement TDocument

The replacement.

options FindOneAndReplaceOptions<TDocument, TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TDocument>

The returned document.

Type Parameters

TDocument

The type of the document.

FindOneAndReplaceAsync<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, IClientSessionHandle, TDocument, FindOneAndReplaceOptions<TDocument, TDocument>, CancellationToken)

Finds a single document and replaces it atomically.

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

Parameters

collection IMongoCollection<TDocument>

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

session IClientSessionHandle

The session.

replacement TDocument

The replacement.

options FindOneAndReplaceOptions<TDocument, TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TDocument>

The returned document.

Type Parameters

TDocument

The type of the document.

FindOneAndReplaceAsync<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, TDocument, FindOneAndReplaceOptions<TDocument, TDocument>, CancellationToken)

Finds a single document and replaces it atomically.

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

Parameters

collection IMongoCollection<TDocument>

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

replacement TDocument

The replacement.

options FindOneAndReplaceOptions<TDocument, TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TDocument>

The returned document.

Type Parameters

TDocument

The type of the document.

FindOneAndReplaceAsync<TDocument, TProjection>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, TDocument, FindOneAndReplaceOptions<TDocument, TProjection>, CancellationToken)

Finds a single document and replaces it atomically.

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

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

replacement TDocument

The replacement.

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

FindOneAndReplaceAsync<TDocument, TProjection>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, TDocument, FindOneAndReplaceOptions<TDocument, TProjection>, CancellationToken)

Finds a single document and replaces it atomically.

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

Parameters

collection IMongoCollection<TDocument>

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

replacement TDocument

The replacement.

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

FindOneAndReplace<TDocument>(IMongoCollection<TDocument>, FilterDefinition<TDocument>, TDocument, FindOneAndReplaceOptions<TDocument, TDocument>, CancellationToken)

Finds a single document and replaces it atomically.

public static TDocument FindOneAndReplace<TDocument>(this IMongoCollection<TDocument> collection, FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TDocument> options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

filter FilterDefinition<TDocument>

The filter.

replacement TDocument

The replacement.

options FindOneAndReplaceOptions<TDocument, TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

TDocument

The returned document.

Type Parameters

TDocument

The type of the document.

FindOneAndReplace<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, FilterDefinition<TDocument>, TDocument, FindOneAndReplaceOptions<TDocument, TDocument>, CancellationToken)

Finds a single document and replaces it atomically.

public static TDocument FindOneAndReplace<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TDocument> options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

filter FilterDefinition<TDocument>

The filter.

replacement TDocument

The replacement.

options FindOneAndReplaceOptions<TDocument, TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

TDocument

The returned document.

Type Parameters

TDocument

The type of the document.

FindOneAndReplace<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, TDocument, FindOneAndReplaceOptions<TDocument, TDocument>, CancellationToken)

Finds a single document and replaces it atomically.

public static TDocument FindOneAndReplace<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TDocument> options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

replacement TDocument

The replacement.

options FindOneAndReplaceOptions<TDocument, TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

TDocument

The returned document.

Type Parameters

TDocument

The type of the document.

FindOneAndReplace<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, TDocument, FindOneAndReplaceOptions<TDocument, TDocument>, CancellationToken)

Finds a single document and replaces it atomically.

public static TDocument FindOneAndReplace<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TDocument> options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

replacement TDocument

The replacement.

options FindOneAndReplaceOptions<TDocument, TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

TDocument

The returned document.

Type Parameters

TDocument

The type of the document.

FindOneAndReplace<TDocument, TProjection>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, TDocument, FindOneAndReplaceOptions<TDocument, TProjection>, CancellationToken)

Finds a single document and replaces it atomically.

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

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

replacement TDocument

The replacement.

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

FindOneAndReplace<TDocument, TProjection>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, TDocument, FindOneAndReplaceOptions<TDocument, TProjection>, CancellationToken)

Finds a single document and replaces it atomically.

public static TProjection FindOneAndReplace<TDocument, TProjection>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

replacement TDocument

The replacement.

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

FindOneAndUpdateAsync<TDocument>(IMongoCollection<TDocument>, FilterDefinition<TDocument>, UpdateDefinition<TDocument>, FindOneAndUpdateOptions<TDocument, TDocument>, CancellationToken)

Finds a single document and updates it atomically.

public static Task<TDocument> FindOneAndUpdateAsync<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 CancellationToken

The cancellation token.

Returns

Task<TDocument>

The returned document.

Type Parameters

TDocument

The type of the document.

FindOneAndUpdateAsync<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, FilterDefinition<TDocument>, UpdateDefinition<TDocument>, FindOneAndUpdateOptions<TDocument, TDocument>, CancellationToken)

Finds a single document and updates it atomically.

public static Task<TDocument> FindOneAndUpdateAsync<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 IClientSessionHandle

The session.

filter FilterDefinition<TDocument>

The filter.

update UpdateDefinition<TDocument>

The update.

options FindOneAndUpdateOptions<TDocument, TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TDocument>

The returned document.

Type Parameters

TDocument

The type of the document.

FindOneAndUpdateAsync<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, UpdateDefinition<TDocument>, FindOneAndUpdateOptions<TDocument, TDocument>, CancellationToken)

Finds a single document and updates it atomically.

public static Task<TDocument> FindOneAndUpdateAsync<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 IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

update UpdateDefinition<TDocument>

The update.

options FindOneAndUpdateOptions<TDocument, TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TDocument>

The returned document.

Type Parameters

TDocument

The type of the document.

FindOneAndUpdateAsync<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, UpdateDefinition<TDocument>, FindOneAndUpdateOptions<TDocument, TDocument>, CancellationToken)

Finds a single document and updates it atomically.

public static Task<TDocument> FindOneAndUpdateAsync<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, 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, TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TDocument>

The returned document.

Type Parameters

TDocument

The type of the document.

FindOneAndUpdateAsync<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 Task<TProjection> FindOneAndUpdateAsync<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 IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

update UpdateDefinition<TDocument>

The update.

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

FindOneAndUpdateAsync<TDocument, TProjection>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, UpdateDefinition<TDocument>, FindOneAndUpdateOptions<TDocument, TProjection>, CancellationToken)

Finds a single document and updates it atomically.

public static Task<TProjection> FindOneAndUpdateAsync<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 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).

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 CancellationToken

The cancellation token.

Returns

TDocument

The returned document.

Type Parameters

TDocument

The type of the document.

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 IClientSessionHandle

The session.

filter FilterDefinition<TDocument>

The filter.

update UpdateDefinition<TDocument>

The update.

options FindOneAndUpdateOptions<TDocument, TDocument>

The options.

cancellationToken CancellationToken

The 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 IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

update UpdateDefinition<TDocument>

The update.

options FindOneAndUpdateOptions<TDocument, TDocument>

The options.

cancellationToken CancellationToken

The 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, 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, 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, TDocument>

The options.

cancellationToken CancellationToken

The 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 IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

update UpdateDefinition<TDocument>

The update.

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

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

FindSync<TDocument>(IMongoCollection<TDocument>, FilterDefinition<TDocument>, FindOptions<TDocument, TDocument>, CancellationToken)

Finds the documents matching the filter.

public static IAsyncCursor<TDocument> FindSync<TDocument>(this IMongoCollection<TDocument> collection, FilterDefinition<TDocument> filter, FindOptions<TDocument, TDocument> options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

filter FilterDefinition<TDocument>

The filter.

options FindOptions<TDocument, TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

IAsyncCursor<TDocument>

A Task whose result is a cursor.

Type Parameters

TDocument

The type of the document.

FindSync<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, FilterDefinition<TDocument>, FindOptions<TDocument, TDocument>, CancellationToken)

Finds the documents matching the filter.

public static IAsyncCursor<TDocument> FindSync<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, FilterDefinition<TDocument> filter, FindOptions<TDocument, TDocument> options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

filter FilterDefinition<TDocument>

The filter.

options FindOptions<TDocument, TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

IAsyncCursor<TDocument>

A Task whose result is a cursor.

Type Parameters

TDocument

The type of the document.

FindSync<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, FindOptions<TDocument, TDocument>, CancellationToken)

Finds the documents matching the filter.

public static IAsyncCursor<TDocument> FindSync<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, FindOptions<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 FindOptions<TDocument, TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

IAsyncCursor<TDocument>

A Task whose result is a cursor.

Type Parameters

TDocument

The type of the document.

FindSync<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, FindOptions<TDocument, TDocument>, CancellationToken)

Finds the documents matching the filter.

public static IAsyncCursor<TDocument> FindSync<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, FindOptions<TDocument, TDocument> options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

options FindOptions<TDocument, TDocument>

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

IAsyncCursor<TDocument>

A Task whose result is a cursor.

Type Parameters

TDocument

The type of the document.

Find<TDocument>(IMongoCollection<TDocument>, FilterDefinition<TDocument>, FindOptions)

Begins a fluent find interface.

public static IFindFluent<TDocument, TDocument> Find<TDocument>(this IMongoCollection<TDocument> collection, FilterDefinition<TDocument> filter, FindOptions options = null)

Parameters

collection IMongoCollection<TDocument>

The collection.

filter FilterDefinition<TDocument>

The filter.

options FindOptions

The options.

Returns

IFindFluent<TDocument, TDocument>

A fluent find interface.

Type Parameters

TDocument

The type of the document.

Find<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, FilterDefinition<TDocument>, FindOptions)

Begins a fluent find interface.

public static IFindFluent<TDocument, TDocument> Find<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, FilterDefinition<TDocument> filter, FindOptions options = null)

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

filter FilterDefinition<TDocument>

The filter.

options FindOptions

The options.

Returns

IFindFluent<TDocument, TDocument>

A fluent find interface.

Type Parameters

TDocument

The type of the document.

Find<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, FindOptions)

Begins a fluent find interface.

public static IFindFluent<TDocument, TDocument> Find<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, FindOptions options = null)

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

options FindOptions

The options.

Returns

IFindFluent<TDocument, TDocument>

A fluent interface.

Type Parameters

TDocument

The type of the document.

Find<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, FindOptions)

Begins a fluent find interface.

public static IFindFluent<TDocument, TDocument> Find<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, FindOptions options = null)

Parameters

collection IMongoCollection<TDocument>

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

options FindOptions

The options.

Returns

IFindFluent<TDocument, TDocument>

A fluent interface.

Type Parameters

TDocument

The type of the document.

ReplaceOneAsync<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, TDocument, ReplaceOptions, CancellationToken)

Replaces a single document.

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

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

replacement TDocument

The replacement.

options ReplaceOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<ReplaceOneResult>

The result of the replacement.

Type Parameters

TDocument

The type of the document.

ReplaceOneAsync<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, TDocument, UpdateOptions, CancellationToken)

Replaces a single document.

[Obsolete("Use the overload that takes a ReplaceOptions instead of an UpdateOptions.")]
public static Task<ReplaceOneResult> ReplaceOneAsync<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

replacement TDocument

The replacement.

options UpdateOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<ReplaceOneResult>

The result of the replacement.

Type Parameters

TDocument

The type of the document.

ReplaceOneAsync<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, TDocument, ReplaceOptions, CancellationToken)

Replaces a single document.

public static Task<ReplaceOneResult> ReplaceOneAsync<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

replacement TDocument

The replacement.

options ReplaceOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<ReplaceOneResult>

The result of the replacement.

Type Parameters

TDocument

The type of the document.

ReplaceOneAsync<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, TDocument, UpdateOptions, CancellationToken)

Replaces a single document.

[Obsolete("Use the overload that takes a ReplaceOptions instead of an UpdateOptions.")]
public static Task<ReplaceOneResult> ReplaceOneAsync<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

replacement TDocument

The replacement.

options UpdateOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<ReplaceOneResult>

The result of the replacement.

Type Parameters

TDocument

The type of the document.

ReplaceOne<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, TDocument, ReplaceOptions, CancellationToken)

Replaces a single document.

public static ReplaceOneResult ReplaceOne<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

replacement TDocument

The replacement.

options ReplaceOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

ReplaceOneResult

The result of the replacement.

Type Parameters

TDocument

The type of the document.

ReplaceOne<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, TDocument, UpdateOptions, CancellationToken)

Replaces a single document.

[Obsolete("Use the overload that takes a ReplaceOptions instead of an UpdateOptions.")]
public static ReplaceOneResult ReplaceOne<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, Expression<Func<TDocument, bool>> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

replacement TDocument

The replacement.

options UpdateOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

ReplaceOneResult

The result of the replacement.

Type Parameters

TDocument

The type of the document.

ReplaceOne<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, TDocument, ReplaceOptions, CancellationToken)

Replaces a single document.

public static ReplaceOneResult ReplaceOne<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

replacement TDocument

The replacement.

options ReplaceOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

ReplaceOneResult

The result of the replacement.

Type Parameters

TDocument

The type of the document.

ReplaceOne<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, TDocument, UpdateOptions, CancellationToken)

Replaces a single document.

[Obsolete("Use the overload that takes a ReplaceOptions instead of an UpdateOptions.")]
public static ReplaceOneResult ReplaceOne<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

replacement TDocument

The replacement.

options UpdateOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

ReplaceOneResult

The result of the replacement.

Type Parameters

TDocument

The type of the document.

UpdateManyAsync<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, UpdateDefinition<TDocument>, UpdateOptions, CancellationToken)

Updates many documents.

public static Task<UpdateResult> UpdateManyAsync<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 IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

update UpdateDefinition<TDocument>

The update.

options UpdateOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<UpdateResult>

The result of the update operation.

Type Parameters

TDocument

The type of the document.

UpdateManyAsync<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, UpdateDefinition<TDocument>, UpdateOptions, CancellationToken)

Updates many documents.

public static Task<UpdateResult> UpdateManyAsync<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 UpdateOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<UpdateResult>

The result of the update operation.

Type Parameters

TDocument

The type of the document.

UpdateMany<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, Expression<Func<TDocument, bool>>, UpdateDefinition<TDocument>, UpdateOptions, CancellationToken)

Updates many documents.

public static UpdateResult UpdateMany<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 IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

update UpdateDefinition<TDocument>

The update.

options UpdateOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

UpdateResult

The result of the update operation.

Type Parameters

TDocument

The type of the document.

UpdateMany<TDocument>(IMongoCollection<TDocument>, Expression<Func<TDocument, bool>>, UpdateDefinition<TDocument>, UpdateOptions, CancellationToken)

Updates many documents.

public static UpdateResult UpdateMany<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 UpdateOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

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 IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

update UpdateDefinition<TDocument>

The update.

options UpdateOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<UpdateResult>

The result of the update operation.

Type Parameters

TDocument

The type of the document.

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 UpdateOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<UpdateResult>

The result of the update operation.

Type Parameters

TDocument

The 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

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

filter Expression<Func<TDocument, bool>>

The filter.

update UpdateDefinition<TDocument>

The update.

options UpdateOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

UpdateResult

The result of the update operation.

Type Parameters

TDocument

The type of the document.

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

collection IMongoCollection<TDocument>

The collection.

filter Expression<Func<TDocument, bool>>

The filter.

update UpdateDefinition<TDocument>

The update.

options UpdateOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

UpdateResult

The result of the update operation.

Type Parameters

TDocument

The type of the document.

WatchAsync<TDocument>(IMongoCollection<TDocument>, ChangeStreamOptions, CancellationToken)

Watches changes on the collection.

public static Task<IChangeStreamCursor<ChangeStreamDocument<TDocument>>> WatchAsync<TDocument>(this IMongoCollection<TDocument> collection, ChangeStreamOptions options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

options ChangeStreamOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<IChangeStreamCursor<ChangeStreamDocument<TDocument>>>

A change stream.

Type Parameters

TDocument

The type of the document.

WatchAsync<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, ChangeStreamOptions, CancellationToken)

Watches changes on the collection.

public static Task<IChangeStreamCursor<ChangeStreamDocument<TDocument>>> WatchAsync<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, ChangeStreamOptions options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

options ChangeStreamOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<IChangeStreamCursor<ChangeStreamDocument<TDocument>>>

A change stream.

Type Parameters

TDocument

The type of the document.

Watch<TDocument>(IMongoCollection<TDocument>, ChangeStreamOptions, CancellationToken)

Watches changes on the collection.

public static IChangeStreamCursor<ChangeStreamDocument<TDocument>> Watch<TDocument>(this IMongoCollection<TDocument> collection, ChangeStreamOptions options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

options ChangeStreamOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

IChangeStreamCursor<ChangeStreamDocument<TDocument>>

A change stream.

Type Parameters

TDocument

The type of the document.

Watch<TDocument>(IMongoCollection<TDocument>, IClientSessionHandle, ChangeStreamOptions, CancellationToken)

Watches changes on the collection.

public static IChangeStreamCursor<ChangeStreamDocument<TDocument>> Watch<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, ChangeStreamOptions options = null, CancellationToken cancellationToken = default)

Parameters

collection IMongoCollection<TDocument>

The collection.

session IClientSessionHandle

The session.

options ChangeStreamOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

IChangeStreamCursor<ChangeStreamDocument<TDocument>>

A change stream.

Type Parameters

TDocument

The type of the document.