count Documents
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 |
+-------------+--------------------------------+
Content copied to clipboard
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 |
+-------------+--------------------------------+
Content copied to clipboard
Return
the number of documents in the collection
Parameters
client Session
the client session with which to associate this operation
filter
the query filter
options
the options describing the count