countDocuments

abstract suspend fun countDocuments(): Long

Counts the number of documents in the collection.

Note: When migrating from count() to countDocuments() the following query operators must be replaced:

+-------------+--------------------------------+
| Operator | Replacement |
+=============+================================+
| $where | $expr |
+-------------+--------------------------------+
| $near | $geoWithin with $center |
+-------------+--------------------------------+
| $nearSphere | $geoWithin with $centerSphere |
+-------------+--------------------------------+

Since

3.8


abstract suspend fun countDocuments(filter: Bson): Long

Counts the number of documents in the collection according to the given options.

Note: When migrating from count() to countDocuments() the following query operators must be replaced:

+-------------+--------------------------------+
| Operator | Replacement |
+=============+================================+
| $where | $expr |
+-------------+--------------------------------+
| $near | $geoWithin with $center |
+-------------+--------------------------------+
| $nearSphere | $geoWithin with $centerSphere |
+-------------+--------------------------------+

Since

3.8

Parameters

filter

the query filter


abstract suspend fun countDocuments(filter: Bson, options: CountOptions): Long

Counts the number of documents in the collection according to the given options.

Note: When migrating from count() to countDocuments() the following query operators must be replaced:

+-------------+--------------------------------+
| Operator | Replacement |
+=============+================================+
| $where | $expr |
+-------------+--------------------------------+
| $near | $geoWithin with $center |
+-------------+--------------------------------+
| $nearSphere | $geoWithin with $centerSphere |
+-------------+--------------------------------+

Since

3.8

Parameters

filter

the query filter

options

the options describing the count


abstract suspend fun countDocuments(clientSession: ClientSession): Long

Counts the number of documents in the collection.

Note: When migrating from count() to countDocuments() the following query operators must be replaced:

+-------------+--------------------------------+
| Operator | Replacement |
+=============+================================+
| $where | $expr |
+-------------+--------------------------------+
| $near | $geoWithin with $center |
+-------------+--------------------------------+
| $nearSphere | $geoWithin with $centerSphere |
+-------------+--------------------------------+

Since

3.8

Parameters

clientSession

the client session with which to associate this operation


abstract suspend fun countDocuments(clientSession: ClientSession, filter: Bson): Long

Counts the number of documents in the collection according to the given options.

Note: When migrating from count() to countDocuments() the following query operators must be replaced:

+-------------+--------------------------------+
| Operator | Replacement |
+=============+================================+
| $where | $expr |
+-------------+--------------------------------+
| $near | $geoWithin with $center |
+-------------+--------------------------------+
| $nearSphere | $geoWithin with $centerSphere |
+-------------+--------------------------------+

Since

3.8

Parameters

clientSession

the client session with which to associate this operation

filter

the query filter


abstract suspend fun countDocuments(    clientSession: ClientSession,     filter: Bson,     options: CountOptions): Long

Counts the number of documents in the collection according to the given options.

Note: When migrating from count() to countDocuments() the following query operators must be replaced:

+-------------+--------------------------------+
| Operator | Replacement |
+=============+================================+
| $where | $expr |
+-------------+--------------------------------+
| $near | $geoWithin with $center |
+-------------+--------------------------------+
| $nearSphere | $geoWithin with $centerSphere |
+-------------+--------------------------------+

Since

3.8

Parameters

clientSession

the client session with which to associate this operation

filter

the query filter

options

the options describing the count