Table of Contents

Method CountDocuments

Namespace
MongoDB.Driver
Assembly
MongoDB.Driver.dll

CountDocuments(CancellationToken)

Counts the number of documents.

long CountDocuments(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

The cancellation token.

Returns

long

The count.

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