Method CountDocuments
CountDocuments(FilterDefinition<TDocument>, 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 virtual long CountDocuments(FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default)
Parameters
filter
FilterDefinition<TDocument>The filter.
options
CountOptionsThe options.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- long
The number of documents in the collection.
Remarks
Note: when migrating from Count to CountDocuments the following query operations must be replaced:
+-------------+--------------------------------+
| Operator | Replacement |
+=============+================================+
| $where | $expr |
+-------------+--------------------------------+
| $near | $geoWithin with $center |
+-------------+--------------------------------+
| $nearSphere | $geoWithin with $centerSphere |
+-------------+--------------------------------+
CountDocuments(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 EstimatedDocumentCount(EstimatedDocumentCountOptions, CancellationToken).
public virtual long CountDocuments(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
- long
The number of documents in the collection.
Remarks
Note: when migrating from Count to CountDocuments the following query operations must be replaced:
+-------------+--------------------------------+
| Operator | Replacement |
+=============+================================+
| $where | $expr |
+-------------+--------------------------------+
| $near | $geoWithin with $center |
+-------------+--------------------------------+
| $nearSphere | $geoWithin with $centerSphere |
+-------------+--------------------------------+