Method Count

| MongoDB CSharp Driver API Reference (original) (raw)

Namespace

MongoDB.Driver

Assembly

MongoDB.Driver.dll

Count(IMongoCollection, 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

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(IMongoCollection, 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

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.