44Read Data from MongoDB
55======================
66
7+ .. contents:: On this page
8+ :local:
9+ :backlinks: none
10+ :depth: 2
11+ :class: singlecol
12+
13+ .. facet::
14+ :name: genre
15+ :values: reference
16+
717.. meta::
8- :description: Learn how to use (+driver-short+} to read data from MongoDB.
18+ :description: Learn how to use {+driver-short+} to read data from MongoDB.
19+ :keywords: usage examples, query, find, code example
920
1021.. toctree::
1122 :titlesonly:
@@ -19,11 +30,100 @@ Read Data from MongoDB
1930 /read/distinct
2031 /read/cursors
2132
22- - :ref:`pymongo-specify-query`
23- - :ref:`pymongo-retrieve`
24- - :ref:`pymongo-project`
25- - :ref:`pymongo-specify-documents-to-return`
26- - :ref:`pymongo-count`
27- - :ref:`pymongo-distinct`
28- - :ref:`pymongo-cursors`
33+ Overview
34+ --------
35+
36+ On this page, you can see copyable code examples that show common
37+ methods you can use to retrieve documents with {+driver-short+}.
38+
39+ .. tip::
40+
41+ To learn more about any of the methods shown on this page, see the link
42+ provided in each section.
43+
44+ To use an example from this page, copy the code example into the
45+ :ref:`sample application <pymongo-read-sample>` or your own application.
46+ Be sure to replace all placeholders in the code examples, such as ``<connection string URI>``, with
47+ the relevant values for your MongoDB deployment.
48+
49+ .. _pymongo-read-sample:
50+
51+ .. include:: /includes/usage-examples/sample-app-intro.rst
52+
53+ .. literalinclude:: /includes/usage-examples/read-sample-app.py
54+ :language: python
55+ :copyable:
56+ :linenos:
57+ :emphasize-lines: 10-12
58+
59+ Find One
60+ --------
61+
62+ .. literalinclude:: /includes/usage-examples/retrieve-code-examples.py
63+ :start-after: start-find-one
64+ :end-before: end-find-one
65+ :language: python
66+ :copyable:
67+
68+ To learn more about the ``find_one()`` method, see :ref:`pymongo-retrieve-find-one` in
69+ the Retrieve Data guide.
70+
71+ Find Multiple
72+ -------------
73+
74+ .. literalinclude:: /includes/usage-examples/retrieve-code-examples.py
75+ :start-after: start-find
76+ :end-before: end-find
77+ :language: python
78+ :copyable:
79+
80+ To learn more about the ``find()`` method, see :ref:`pymongo-retrieve-find-multiple` in
81+ the Retrieve Data guide.
82+
83+ Count Documents in a Collection
84+ -------------------------------
85+
86+ .. literalinclude:: /includes/usage-examples/retrieve-code-examples.py
87+ :start-after: start-count-all
88+ :end-before: end-count-all
89+ :language: python
90+ :copyable:
91+
92+ To learn more about the ``count_documents()`` method, see the
93+ :ref:`pymongo-accurate-count` guide.
94+
95+ Count Documents Returned from a Query
96+ -------------------------------------
97+
98+ .. literalinclude:: /includes/usage-examples/retrieve-code-examples.py
99+ :start-after: start-count-query
100+ :end-before: end-count-query
101+ :language: python
102+ :copyable:
103+
104+ To learn more about the ``count_documents()`` method, see the
105+ :ref:`pymongo-accurate-count` guide.
106+
107+ Estimated Document Count
108+ ------------------------
109+
110+ .. literalinclude:: /includes/usage-examples/retrieve-code-examples.py
111+ :start-after: start-estimated-count
112+ :end-before: end-estimated-count
113+ :language: python
114+ :copyable:
115+
116+ To learn more about the ``estimated_document_count()`` method, see the
117+ :ref:`pymongo-estimated-count` guide.
118+
119+ Retrieve Distinct Values
120+ ------------------------
121+
122+ .. literalinclude:: /includes/usage-examples/retrieve-code-examples.py
123+ :start-after: start-distinct
124+ :end-before: end-distinct
125+ :language: python
126+ :copyable:
29127
128+ To learn more about the ``distinct()`` method, see the
129+ :ref:`pymongo-distinct` guide.
0 commit comments