Skip to content

Commit ae05e90

Browse files
committed
Merge pull request #555
2 parents 3437688 + 1515b02 commit ae05e90

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

docs/reference/method/MongoDBCollection-count.txt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
MongoDB\\Collection::count()
33
============================
44

5+
.. deprecated:: 1.4
6+
57
.. default-domain:: mongodb
68

79
.. contents:: On this page
@@ -45,12 +47,24 @@ Errors/Exceptions
4547
Behavior
4648
--------
4749

48-
.. include:: /includes/extracts/note-bson-comparison.rst
50+
This method is deprecated and cannot be executed within a transaction. It has
51+
always been implemented using the :manual:`count </reference/command/count>`
52+
command. The behavior of the ``count`` command differs depending on the options
53+
passed to it and may or may not provide an accurate count. When no query filter
54+
is provided, the ``count`` command provides an estimate using collection
55+
metadata. Even when provided with a query filter the ``count`` command can
56+
return inaccurate results with a sharded cluster if orphaned documents exist or
57+
if a chunk migration is in progress. The
58+
:phpmethod:`MongoDB\\Collection::countDocuments()` method avoids these sharded
59+
cluster problems entirely when used with MongoDB 3.6+, and when a primary read
60+
preference with older sharded clusters.
4961

50-
.. todo: add output and examples
62+
.. include:: /includes/extracts/note-bson-comparison.rst
5163

5264
See Also
5365
--------
5466

5567
- :manual:`count </reference/command/count>` command reference in the MongoDB
5668
manual
69+
- :phpmethod:`MongoDB\\Collection::countDocuments()`
70+
- :phpmethod:`MongoDB\\Collection::estimatedDocumentCount()`

docs/reference/method/MongoDBCollection-countDocuments.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ Errors/Exceptions
4747
Behavior
4848
--------
4949

50-
.. include:: /includes/extracts/note-bson-comparison.rst
51-
5250
Internally, this method uses the ``$group`` aggregation pipeline operator to
5351
obtain the result. If a ``filter`` parameter is given, this is converted into
5452
a ``$match`` pipeline operator. Optional ``$skip`` and ``$limit`` stages are
@@ -73,4 +71,11 @@ Consider the following alternatives to these restricted operators:
7371
* - :query:`$where`
7472
- :query:`$expr` (requires MongoDB 3.6+)
7573

74+
.. include:: /includes/extracts/note-bson-comparison.rst
75+
7676
.. todo: add output and examples
77+
78+
See Also
79+
--------
80+
81+
- :phpmethod:`MongoDB\\Collection::estimatedDocumentCount()`

docs/reference/method/MongoDBCollection-estimatedDocumentCount.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,14 @@ Errors/Exceptions
4747
Behavior
4848
--------
4949

50-
.. include:: /includes/extracts/note-bson-comparison.rst
50+
This method returns an estimate of the count of documents in the collection
51+
using collection metadata, rather than counting the documents or consulting an
52+
index. This method does not take a ``session`` option and cannot be executed
53+
within a transaction.
5154

5255
See Also
5356
--------
5457

5558
- :manual:`count </reference/command/count>` command reference in the MongoDB
5659
manual
60+
- :phpmethod:`MongoDB\\Collection::countDocuments()`

0 commit comments

Comments
 (0)