Skip to content

Commit e4abb44

Browse files
committed
PHPLIB-434: Add note about performance of countDocuments
1 parent 632cd8b commit e4abb44

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

docs/reference/method/MongoDBCollection-countDocuments.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ obtain the result. If a ``filter`` parameter is given, this is converted into
5252
a ``$match`` pipeline operator. Optional ``$skip`` and ``$limit`` stages are
5353
added between ``$match`` and ``group`` if present in the options.
5454

55+
.. note::
56+
57+
This function counts documents on the server side. To obtain the total number
58+
of documents without filters, the
59+
:phpmethod:`MongoDB\\Collection::estimatedDocumentCount()` method can be
60+
used. This method estimates the number of documents based on collection
61+
metadata, thus sacrificing accuracy for performance.
62+
5563
Since this method uses an aggregation pipeline, some query operators accepted
5664
within a :phpmethod:`MongoDB\\Collection::count()` ``filter`` cannot be used.
5765
Consider the following alternatives to these restricted operators:

0 commit comments

Comments
 (0)