Skip to content

Commit ace08f7

Browse files
DOCSP-36989 Count (#16)
1 parent 4286055 commit ace08f7

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

source/fundamentals/crud/count.txt

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,43 @@
11
.. uses tutorial.rst
22

3-
If we just want to know how many documents match a query we can
4-
perform a the ``~pymongo.collection.Collection.count_documents`` method operation
5-
instead of a full query. We can get a count of all of the documents
6-
in a collection:
3+
.. _pymongo-count:
4+
5+
=====
6+
Count
7+
=====
8+
9+
.. contents:: On this page
10+
:local:
11+
:backlinks: none
12+
:depth: 1
13+
:class: singlecol
14+
15+
.. facet::
16+
:name: genre
17+
:values: reference
18+
19+
.. meta::
20+
:keywords: number, amount
21+
22+
To see how many documents are in a collection, use the
23+
``~pymongo.collection.Collection.count_documents()`` method.
24+
25+
Count All Documents
26+
-------------------
27+
28+
To return a count of all documents in the collection, pass an empty object to
29+
the ``count_documents()`` method, as shown in the following example:
730

831
.. code-block:: python
932

1033
>> posts.count_documents({})
1134
3
1235

13-
or just of those documents that match a specific query:
36+
Count Specific Documents
37+
------------------------
38+
39+
To return a count of documents that match specific search criteria, specify a
40+
query in the ``count_documents()`` method, as shown in the following example:
1441

1542
.. code-block:: python
1643

0 commit comments

Comments
 (0)