Method CountDocumentsAsync
CountDocumentsAsync(FilterDefinition<TDocument>, CountOptions, CancellationToken)
Counts the number of documents in the collection.
For a fast estimate of the total documents in a collection see
public virtual Task<long> CountDocumentsAsync(FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition<TDocument>The filter.
options
CountOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
Remarks
Note: when migrating from CountAsync to CountDocumentsAsync the following query operations must be replaced:
+-------------+--------------------------------+
| Operator | Replacement |
+=============+================================+
| $where | $expr |
+-------------+--------------------------------+
| $near | $geoWithin with $center |
+-------------+--------------------------------+
| $nearSphere | $geoWithin with $centerSphere |
+-------------+--------------------------------+
CountDocumentsAsync(IClientSessionHandle, FilterDefinition<TDocument>, 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 virtual Task<long> CountDocumentsAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default)
Parameters
session
IClientSessionHandleThe session.
filter
FilterDefinition<TDocument>The filter.
options
CountOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
Remarks
Note: when migrating from CountAsync to CountDocumentsAsync the following query operations must be replaced:
+-------------+--------------------------------+
| Operator | Replacement |
+=============+================================+
| $where | $expr |
+-------------+--------------------------------+
| $near | $geoWithin with $center |
+-------------+--------------------------------+
| $nearSphere | $geoWithin with $centerSphere |
+-------------+--------------------------------+