Table of Contents

Method CountAsync

Namespace
MongoDB.Driver
Assembly
MongoDB.Driver.dll

CountAsync(FilterDefinition<TDocument>, CountOptions, CancellationToken)

Counts the number of documents in the collection.

[Obsolete("Use CountDocumentsAsync or EstimatedDocumentCountAsync instead.")]
public abstract Task<long> CountAsync(FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default)

Parameters

filter FilterDefinition<TDocument>

The filter.

options CountOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<long>

The number of documents in the collection.

CountAsync(IClientSessionHandle, FilterDefinition<TDocument>, CountOptions, CancellationToken)

Counts the number of documents in the collection.

[Obsolete("Use CountDocumentsAsync or EstimatedDocumentCountAsync instead.")]
public virtual Task<long> CountAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default)

Parameters

session IClientSessionHandle

The session.

filter FilterDefinition<TDocument>

The filter.

options CountOptions

The options.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<long>

The number of documents in the collection.