@@ -266,7 +266,8 @@ Collection Bulk Write Example
266266
267267The 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
291292The following example performs multiple write operations on the
292293``sample_restaurants.restaurants`` and ``sample_mflix.movies``
293294namespaces 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
364366The 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+
374391If any of the write operations in an unordered bulk write fail, {+driver-short+}
375392reports the errors only after attempting all operations.
376393
@@ -436,7 +453,8 @@ to the ``MongoClient.bulk_write()`` method:
436453
437454The 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+
459522Return Values
460523-------------
461524
0 commit comments