Table of Contents

Method CountDocumentsAsync

Namespace
MongoDB.Driver
Assembly
MongoDB.Driver.dll

CountDocumentsAsync(CancellationToken)

Counts the number of documents.

public virtual Task<long> CountDocumentsAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

The cancellation token.

Returns

Task<long>

A Task whose result is the count.

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 |
+-------------+--------------------------------+