@@ -21,18 +21,22 @@ Overview
21
21
---------
22
22
23
23
In this guide, you can learn how to use the {+php-library+} to retrieve an accurate
24
- and estimated count of the number of documents in a collection. The ``MongoDB\Collection::countDocuments()``
25
- method returns the exact number of documents that match a query filter or that exist in
26
- a collection, and the ``MongoDB\Collection::estimatedDocumentCount()`` method returns
27
- the estimated number of documents in a collection.
24
+ and estimated count of the number of documents in a collection. The following methods
25
+ count documents in a collection:
26
+
27
+ - ``MongoDB\Collection::countDocuments()``: Returns the exact number of documents that
28
+ match a query filter or that exist in a collection
29
+
30
+ - ``MongoDB\Collection::estimatedDocumentCount()``: Returns the estimated number of documents
31
+ in a collection
28
32
29
33
Sample Data
30
34
~~~~~~~~~~~
31
35
32
36
The examples in this guide use the ``companies`` collection in the ``sample_training``
33
37
database from the :atlas:`Atlas sample datasets </sample-data>`. To access this collection
34
38
from your PHP application, instantiate a ``MongoDB\Client`` that connects to an Atlas cluster
35
- and assign the following values to your ``db`` and `` collection`` variables :
39
+ and assign the following value to your ``collection`` variable :
36
40
37
41
.. literalinclude:: /includes/read/count.php
38
42
:language: php
@@ -80,8 +84,8 @@ Count Specific Documents
80
84
To return a count of documents that match specific search criteria, pass a query
81
85
filter to the ``countDocuments()`` method.
82
86
83
- The following example counts the number of documents that have a ``founded_year``
84
- value of ``2010``:
87
+ The following example counts the number of documents in which the value of the
88
+ ``founded_year`` field is ``2010``:
85
89
86
90
.. io-code-block::
87
91
:copyable:
@@ -101,8 +105,8 @@ Customize Count Behavior
101
105
~~~~~~~~~~~~~~~~~~~~~~~~
102
106
103
107
You can modify the behavior of the ``countDocuments()`` method by
104
- passing an array that specifies option values as a parameter . The
105
- following table describes some options you can set in the array :
108
+ passing an array that specifies option values. The following table
109
+ describes some options you can set to customize the count operation :
106
110
107
111
.. list-table::
108
112
:widths: 30 70
@@ -164,9 +168,9 @@ Retrieve an Estimated Count
164
168
---------------------------
165
169
166
170
You can retrieve an estimate of the number of documents in a collection by calling
167
- the ``estimatedDocumentCount()`` method. The method estimates the amount of
168
- documents based on collection metadata, which might be faster than performing an
169
- accurate count.
171
+ the ``MongoDB\Collection:: estimatedDocumentCount()`` method. The method estimates
172
+ the amount of documents based on collection metadata, which might be faster than
173
+ performing an accurate count.
170
174
171
175
The following example estimates the number of documents in a collection:
172
176
@@ -221,8 +225,8 @@ following table describes the options you can set in the array:
221
225
| **Type**: ``MongoDB\Driver\Session``
222
226
223
227
The following example uses the ``estimatedDocumentCount()`` method to return an
224
- estimate of the number of documents in the collection and instructs the operation
225
- to run for a maximum of ``1000`` milliseconds:
228
+ estimate of the number of documents in the collection and sets a timeout of
229
+ ``1000`` milliseconds on the operation :
226
230
227
231
.. io-code-block::
228
232
:copyable:
0 commit comments