Skip to content

Commit 3084a68

Browse files
committed
DOCSP-48162: Async examples for Write pages
1 parent e699450 commit 3084a68

File tree

12 files changed

+957
-223
lines changed

12 files changed

+957
-223
lines changed

source/crud/bulk-write.txt

Lines changed: 72 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ Collection Bulk Write Example
266266

267267
The following example performs multiple write operations on the
268268
``restaurants`` collection by using the ``bulk_write()`` method
269-
on a ``Collection`` instance:
269+
on a ``Collection`` instance. Select the
270+
:guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding code:
270271

271272
.. io-code-block::
272273
:copyable:
@@ -291,7 +292,8 @@ Client Bulk Write Example
291292
The following example performs multiple write operations on the
292293
``sample_restaurants.restaurants`` and ``sample_mflix.movies``
293294
namespaces by using the ``bulk_write()`` method on a ``MongoClient``
294-
instance:
295+
instance. Select the
296+
:guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding code:
295297

296298
.. io-code-block::
297299
:copyable:
@@ -363,14 +365,29 @@ to the ``Collection.bulk_write()`` method:
363365

364366
The following example calls the ``bulk_write()`` method from the preceding
365367
:ref:`pymongo-bulk-write-collection-ex` but sets the ``ordered`` option
366-
to ``False``:
368+
to ``False``. Select the
369+
:guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding code:
367370

368-
.. literalinclude:: /includes/write/bulk-write.py
369-
:start-after: start-bulk-write-unordered
370-
:end-before: end-bulk-write-unordered
371-
:language: python
372-
:copyable:
371+
.. tabs::
372+
373+
.. tab:: Synchronous
374+
:tabid: sync
373375

376+
.. literalinclude:: /includes/write/bulk-write.py
377+
:start-after: start-bulk-write-unordered
378+
:end-before: end-bulk-write-unordered
379+
:language: python
380+
:copyable:
381+
382+
.. tab:: Asynchronous
383+
:tabid: async
384+
385+
.. literalinclude:: /includes/write/bulk-write-async.py
386+
:start-after: start-bulk-write-unordered
387+
:end-before: end-bulk-write-unordered
388+
:language: python
389+
:copyable:
390+
374391
If any of the write operations in an unordered bulk write fail, {+driver-short+}
375392
reports the errors only after attempting all operations.
376393

@@ -436,7 +453,8 @@ to the ``MongoClient.bulk_write()`` method:
436453

437454
The following example calls the ``bulk_write()`` method from the preceding
438455
:ref:`pymongo-bulk-write-client-ex` but sets the ``verbose_results`` option
439-
to ``True``:
456+
to ``True``. Select the
457+
:guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding code:
440458

441459
.. io-code-block::
442460
:copyable:
@@ -456,6 +474,51 @@ to ``True``:
456474
'nModified': 1}, acknowledged=True)}, 'deleteResults': {2: DeleteResult({'ok': 1.0,
457475
'idx': 2, 'n': 344}, acknowledged=True)}}, acknowledged=True, verbose=True)
458476

477+
.. tabs::
478+
479+
.. tab:: Synchronous
480+
:tabid: sync
481+
482+
.. io-code-block::
483+
:copyable:
484+
485+
.. input:: /includes/write/bulk-write.py
486+
:start-after: start-bulk-write-verbose
487+
:end-before: end-bulk-write-verbose
488+
:language: python
489+
490+
.. output::
491+
:visible: false
492+
493+
ClientBulkWriteResult({'anySuccessful': True, 'error': None, 'writeErrors': [],
494+
'writeConcernErrors': [], 'nInserted': 1, 'nUpserted': 0, 'nMatched': 1, 'nModified': 1,
495+
'nDeleted': 344, 'insertResults': {0: InsertOneResult(ObjectId('...'),
496+
acknowledged=True)}, 'updateResults': {1: UpdateResult({'ok': 1.0, 'idx': 1, 'n': 1,
497+
'nModified': 1}, acknowledged=True)}, 'deleteResults': {2: DeleteResult({'ok': 1.0,
498+
'idx': 2, 'n': 344}, acknowledged=True)}}, acknowledged=True, verbose=True)
499+
500+
.. tab:: Asynchronous
501+
:tabid: async
502+
503+
.. io-code-block::
504+
:copyable:
505+
506+
.. input:: /includes/write/bulk-write-async.py
507+
:start-after: start-bulk-write-verbose
508+
:end-before: end-bulk-write-verbose
509+
:language: python
510+
511+
.. output::
512+
:visible: false
513+
514+
ClientBulkWriteResult({'anySuccessful': True, 'error': None, 'writeErrors': [],
515+
'writeConcernErrors': [], 'nInserted': 1, 'nUpserted': 0, 'nMatched': 1, 'nModified': 1,
516+
'nDeleted': 344, 'insertResults': {0: InsertOneResult(ObjectId('...'),
517+
acknowledged=True)}, 'updateResults': {1: UpdateResult({'ok': 1.0, 'idx': 1, 'n': 1,
518+
'nModified': 1}, acknowledged=True)}, 'deleteResults': {2: DeleteResult({'ok': 1.0,
519+
'idx': 2, 'n': 344}, acknowledged=True)}}, acknowledged=True, verbose=True)
520+
521+
459522
Return Values
460523
-------------
461524

source/crud/delete.txt

Lines changed: 84 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -64,25 +64,55 @@ Delete One Document
6464
~~~~~~~~~~~~~~~~~~~
6565

6666
The following example uses the ``delete_one()`` method to remove a document in
67-
the ``restaurants`` collection with a ``name`` value of ``"Ready Penny Inn"``:
67+
the ``restaurants`` collection with a ``name`` value of ``"Ready Penny Inn"``. Select the
68+
:guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding code:
6869

69-
.. literalinclude:: /includes/write/delete.py
70-
:start-after: start-delete-one
71-
:end-before: end-delete-one
72-
:language: python
73-
:copyable:
70+
.. tabs::
71+
72+
.. tab:: Synchronous
73+
:tabid: sync
74+
75+
.. literalinclude:: /includes/write/delete.py
76+
:start-after: start-delete-one
77+
:end-before: end-delete-one
78+
:language: python
79+
:copyable:
80+
81+
.. tab:: Asynchronous
82+
:tabid: async
83+
84+
.. literalinclude:: /includes/write/delete-async.py
85+
:start-after: start-delete-one
86+
:end-before: end-delete-one
87+
:language: python
88+
:copyable:
7489

7590
Delete Multiple Documents
7691
~~~~~~~~~~~~~~~~~~~~~~~~~
7792

7893
The following example uses the ``delete_many()`` method to remove all documents
79-
in the ``restaurants`` collection with a ``borough`` value of ``"Brooklyn"``:
94+
in the ``restaurants`` collection with a ``borough`` value of ``"Brooklyn"``. Select the
95+
:guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding code:
96+
97+
.. tabs::
98+
99+
.. tab:: Synchronous
100+
:tabid: sync
101+
102+
.. literalinclude:: /includes/write/delete.py
103+
:start-after: start-delete-many
104+
:end-before: end-delete-many
105+
:language: python
106+
:copyable:
107+
108+
.. tab:: Asynchronous
109+
:tabid: async
80110

81-
.. literalinclude:: /includes/write/delete.py
82-
:start-after: start-delete-many
83-
:end-before: end-delete-many
84-
:language: python
85-
:copyable:
111+
.. literalinclude:: /includes/write/delete-async.py
112+
:start-after: start-delete-many
113+
:end-before: end-delete-many
114+
:language: python
115+
:copyable:
86116

87117
Customize the Delete Operation
88118
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -125,13 +155,28 @@ the delete operation.
125155

126156
The following code uses the ``delete_many()`` method to delete all documents in
127157
the ``restaurants`` collection with a ``name`` value that includes the string ``"Mongo"``.
128-
It also uses the ``comment`` option to add a comment to the operation:
158+
It also uses the ``comment`` option to add a comment to the operation. Select the
159+
:guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding code:
129160

130-
.. literalinclude:: /includes/write/delete.py
131-
:start-after: start-delete-options
132-
:end-before: end-delete-options
133-
:language: python
134-
:copyable:
161+
.. tabs::
162+
163+
.. tab:: Synchronous
164+
:tabid: sync
165+
166+
.. literalinclude:: /includes/write/delete.py
167+
:start-after: start-delete-options
168+
:end-before: end-delete-options
169+
:language: python
170+
:copyable:
171+
172+
.. tab:: Asynchronous
173+
:tabid: async
174+
175+
.. literalinclude:: /includes/write/delete-async.py
176+
:start-after: start-delete-options
177+
:end-before: end-delete-options
178+
:language: python
179+
:copyable:
135180

136181
.. tip::
137182

@@ -150,13 +195,28 @@ use.
150195
.. include:: /includes/collation-description.rst
151196

152197
The following example performs the same delete operation as the previous example,
153-
but with a default collation of ``fr_CA``:
198+
but with a default collation of ``fr_CA``. Select the :guilabel:`Synchronous` or
199+
:guilabel:`Asynchronous` tab to see the corresponding code:
200+
201+
.. tabs::
202+
203+
.. tab:: Synchronous
204+
:tabid: sync
205+
206+
.. literalinclude:: /includes/write/delete.py
207+
:start-after: start-delete-many-collation
208+
:end-before: end-delete-many-collation
209+
:language: python
210+
:copyable:
211+
212+
.. tab:: Asynchronous
213+
:tabid: async
154214

155-
.. literalinclude:: /includes/write/delete.py
156-
:start-after: start-delete-many-collation
157-
:end-before: end-delete-many-collation
158-
:language: python
159-
:copyable:
215+
.. literalinclude:: /includes/write/delete-async.py
216+
:start-after: start-delete-many-collation
217+
:end-before: end-delete-many-collation
218+
:language: python
219+
:copyable:
160220

161221
.. include:: /includes/collation-override-note.rst
162222

0 commit comments

Comments
 (0)