Skip to content

Commit 4196a89

Browse files
committed
DOCSP-48163: Add async examples for Read pages
1 parent 1e47976 commit 4196a89

18 files changed

+1490
-364
lines changed

source/crud/query.txt

Lines changed: 136 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -50,81 +50,182 @@ the relevant values for your MongoDB deployment.
5050

5151
.. include:: /includes/usage-examples/sample-app-intro.rst
5252

53-
.. literalinclude:: /includes/usage-examples/crud-sample-app.py
54-
:language: python
55-
:copyable:
56-
:linenos:
57-
:emphasize-lines: 11-13
53+
Select the :guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding
54+
code:
55+
56+
.. tabs::
57+
58+
.. tab:: Synchronous
59+
:tabid: sync
60+
61+
.. literalinclude:: /includes/usage-examples/crud-sample-app.py
62+
:language: python
63+
:copyable:
64+
:linenos:
65+
:emphasize-lines: 11-13
66+
67+
.. tab:: Asynchronous
68+
:tabid: async
69+
70+
.. literalinclude:: /includes/usage-examples/crud-sample-app-async.py
71+
:language: python
72+
:copyable:
73+
:linenos:
74+
:emphasize-lines: 13-15
5875

5976
Find One
6077
--------
6178

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:
79+
.. tabs::
80+
81+
.. tab:: Synchronous
82+
:tabid: sync
83+
84+
.. literalinclude:: /includes/usage-examples/retrieve-code-examples.py
85+
:start-after: start-find-one
86+
:end-before: end-find-one
87+
88+
.. tab:: Asynchronous
89+
:tabid: async
90+
91+
.. literalinclude:: /includes/usage-examples/retrieve-code-examples-async.py
92+
:start-after: start-find-one
93+
:end-before: end-find-one
6794

6895
To learn more about the ``find_one()`` method, see :ref:`pymongo-retrieve-find-one` in
6996
the Retrieve Data guide.
7097

7198
Find Multiple
7299
-------------
73100

74-
.. literalinclude:: /includes/usage-examples/retrieve-code-examples.py
75-
:start-after: start-find
76-
:end-before: end-find
77-
:language: python
78-
:copyable:
101+
.. tabs::
102+
103+
.. tab:: Synchronous
104+
:tabid: sync
105+
106+
.. literalinclude:: /includes/usage-examples/retrieve-code-examples.py
107+
:start-after: start-find
108+
:end-before: end-find
109+
110+
.. tab:: Asynchronous
111+
:tabid: async
112+
113+
.. literalinclude:: /includes/usage-examples/retrieve-code-examples-async.py
114+
:start-after: start-find
115+
:end-before: end-find
79116

80117
To learn more about the ``find()`` method, see :ref:`pymongo-retrieve-find-multiple` in
81118
the Retrieve Data guide.
82119

83120
Count Documents in a Collection
84121
-------------------------------
85122

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:
123+
.. tabs::
124+
125+
.. tab:: Synchronous
126+
:tabid: sync
127+
128+
.. literalinclude:: /includes/usage-examples/retrieve-code-examples.py
129+
:start-after: start-count-all
130+
:end-before: end-count-all
131+
132+
.. tab:: Asynchronous
133+
:tabid: async
134+
135+
.. literalinclude:: /includes/usage-examples/retrieve-code-examples-async.py
136+
:start-after: start-count-all
137+
:end-before: end-count-all
91138

92139
To learn more about the ``count_documents()`` method, see the
93140
:ref:`pymongo-accurate-count` guide.
94141

95142
Count Documents Returned from a Query
96143
-------------------------------------
97144

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:
145+
.. tabs::
146+
147+
.. tab:: Synchronous
148+
:tabid: sync
149+
150+
.. literalinclude:: /includes/usage-examples/retrieve-code-examples.py
151+
:start-after: start-count-query
152+
:end-before: end-count-query
153+
154+
.. tab:: Asynchronous
155+
:tabid: async
156+
157+
.. literalinclude:: /includes/usage-examples/retrieve-code-examples-async.py
158+
:start-after: start-count-query
159+
:end-before: end-count-query
103160

104161
To learn more about the ``count_documents()`` method, see the
105162
:ref:`pymongo-accurate-count` guide.
106163

107164
Estimated Document Count
108165
------------------------
109166

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:
167+
.. tabs::
168+
169+
.. tab:: Synchronous
170+
:tabid: sync
171+
172+
.. literalinclude:: /includes/usage-examples/retrieve-code-examples.py
173+
:start-after: start-estimated-count
174+
:end-before: end-estimated-count
175+
176+
.. tab:: Asynchronous
177+
:tabid: async
178+
179+
.. literalinclude:: /includes/usage-examples/retrieve-code-examples-async.py
180+
:start-after: start-estimated-count
181+
:end-before: end-estimated-count
115182

116183
To learn more about the ``estimated_document_count()`` method, see the
117184
:ref:`pymongo-estimated-count` guide.
118185

119186
Retrieve Distinct Values
120187
------------------------
121188

122-
.. literalinclude:: /includes/usage-examples/retrieve-code-examples.py
123-
:start-after: start-distinct
124-
:end-before: end-distinct
125-
:language: python
126-
:copyable:
189+
.. tabs::
190+
191+
.. tab:: Synchronous
192+
:tabid: sync
193+
194+
.. literalinclude:: /includes/usage-examples/retrieve-code-examples.py
195+
:start-after: start-distinct
196+
:end-before: end-distinct
197+
198+
.. tab:: Asynchronous
199+
:tabid: async
200+
201+
.. literalinclude:: /includes/usage-examples/retrieve-code-examples-async.py
202+
:start-after: start-distinct
203+
:end-before: end-distinct
127204

128205
To learn more about the ``distinct()`` method, see the
129206
:ref:`pymongo-distinct` guide.
130207

208+
<<<<<<< HEAD:source/crud/query.txt
209+
=======
210+
Monitor Data Changes
211+
--------------------
212+
213+
.. tabs::
214+
215+
.. tab:: Synchronous
216+
:tabid: sync
217+
218+
.. literalinclude:: /includes/usage-examples/retrieve-code-examples.py
219+
:start-after: start-watch-for-changes
220+
:end-before: end-watch-for-changes
221+
222+
.. tab:: Asynchronous
223+
:tabid: async
224+
225+
.. literalinclude:: /includes/usage-examples/retrieve-code-examples-async.py
226+
:start-after: start-watch-for-changes
227+
:end-before: end-watch-for-changes
228+
229+
To learn more about the ``watch()`` method, see the
230+
:ref:`pymongo-change-streams` guide.
231+
>>>>>>> 5387503 (DOCSP-48163: Add async examples for Read pages):source/read.txt

source/crud/query/count.txt

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,47 @@ Count All Documents
3939
~~~~~~~~~~~~~~~~~~~
4040

4141
To return a count of all documents in the collection, pass an empty dictionary to
42-
the ``count_documents()`` method, as shown in the following example:
42+
the ``count_documents()`` method, as shown in the following example. Select the
43+
:guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding code:
4344

44-
.. code-block:: python
45+
.. tabs::
4546

46-
collection.count_documents({})
47+
.. tab:: Synchronous
48+
:tabid: sync
49+
50+
.. code-block:: python
51+
52+
collection.count_documents({})
53+
54+
.. tab:: Asynchronous
55+
:tabid: async
56+
57+
.. code-block:: python
58+
59+
await collection.count_documents({})
4760

4861
Count Specific Documents
4962
~~~~~~~~~~~~~~~~~~~~~~~~
5063

5164
To return a count of documents that match specific search criteria, specify your
52-
query in the ``count_documents()`` method, as shown in the following example:
65+
query in the ``count_documents()`` method, as shown in the following example. Select the
66+
:guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding code:
67+
68+
.. tabs::
69+
70+
.. tab:: Synchronous
71+
:tabid: sync
72+
73+
.. code-block:: python
5374

54-
.. code-block:: python
55-
56-
collection.count_documents({ "author": "Mike" })
75+
collection.count_documents({ "author": "Mike" })
76+
77+
.. tab:: Asynchronous
78+
:tabid: async
79+
80+
.. code-block:: python
81+
82+
await collection.count_documents({ "author": "Mike" })
5783

5884
Customize Count Behavior
5985
~~~~~~~~~~~~~~~~~~~~~~~~
@@ -103,11 +129,24 @@ the ``estimated_document_count()`` method. The method estimates the amount of
103129
documents based on collection metadata, which might be faster than performing an
104130
accurate count.
105131

106-
The following example estimates the number of documents in a collection:
132+
The following example estimates the number of documents in a collection. Select the
133+
:guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding code:
134+
135+
.. tabs::
136+
137+
.. tab:: Synchronous
138+
:tabid: sync
139+
140+
.. code-block:: python
141+
142+
collection.estimated_document_count()
143+
144+
.. tab:: Asynchronous
145+
:tabid: async
146+
147+
.. code-block:: python
107148

108-
.. code-block:: python
109-
110-
collection.estimated_document_count()
149+
await collection.estimated_document_count()
111150

112151
Customize Estimated Count Behavior
113152
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)