Method CountDocumentsAsync
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
collectionIMongoCollection<TDocument>The collection.
filterExpression<Func<TDocument, bool>>The filter.
optionsCountOptionsThe options.
cancellationTokenCancellationTokenThe cancellation token.
Returns
Type Parameters
TDocumentThe 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
collectionIMongoCollection<TDocument>The collection.
sessionIClientSessionHandleThe session.
filterExpression<Func<TDocument, bool>>The filter.
optionsCountOptionsThe options.
cancellationTokenCancellationTokenThe cancellation token.
Returns
Type Parameters
TDocumentThe type of the document.