countDocuments

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

Counts the number of documents in the collection.

Note: For a fast count of the total documents in a collection see estimatedDocumentCount. 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 |
+-------------+--------------------------------+

Return

the number of documents in the collection


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

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

Note: For a fast count of the total documents in a collection see estimatedDocumentCount. 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 |
+-------------+--------------------------------+

Return

the number of documents in the collection

Parameters

clientSession

the client session with which to associate this operation

filter

the query filter

options

the options describing the count