@@ -266,22 +266,46 @@ 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 :guilabel:`Synchronous` or :guilabel:`Asynchronous`
270+ tab to see the corresponding code:
270271
271- .. io-code-block::
272- :copyable:
272+ .. tabs::
273273
274- .. input:: /includes/write/bulk-write.py
275- :start-after: start-bulk-write-mixed-collection
276- :end-before: end-bulk-write-mixed-collection
277- :language: python
274+ .. tab:: Synchronous
275+ :tabid: sync
278276
279- .. output::
280- :visible: false
281-
282- BulkWriteResult({'writeErrors': [], 'writeConcernErrors': [], 'nInserted': 2,
283- 'nUpserted': 0, 'nMatched': 2, 'nModified': 2, 'nRemoved': 1, 'upserted': []},
284- acknowledged=True)
277+ .. io-code-block::
278+ :copyable:
279+
280+ .. input:: /includes/write/bulk-write.py
281+ :start-after: start-bulk-write-mixed-collection
282+ :end-before: end-bulk-write-mixed-collection
283+ :language: python
284+
285+ .. output::
286+ :visible: false
287+
288+ BulkWriteResult({'writeErrors': [], 'writeConcernErrors': [], 'nInserted': 2,
289+ 'nUpserted': 0, 'nMatched': 2, 'nModified': 2, 'nRemoved': 1, 'upserted': []},
290+ acknowledged=True)
291+
292+ .. tab:: Asynchronous
293+ :tabid: async
294+
295+ .. io-code-block::
296+ :copyable:
297+
298+ .. input:: /includes/write/bulk-write-async.py
299+ :start-after: start-bulk-write-mixed-collection
300+ :end-before: end-bulk-write-mixed-collection
301+ :language: python
302+
303+ .. output::
304+ :visible: false
305+
306+ BulkWriteResult({'writeErrors': [], 'writeConcernErrors': [], 'nInserted': 2,
307+ 'nUpserted': 0, 'nMatched': 2, 'nModified': 2, 'nRemoved': 1, 'upserted': []},
308+ acknowledged=True)
285309
286310.. _pymongo-bulk-write-client-ex:
287311
@@ -291,23 +315,48 @@ Client Bulk Write Example
291315The following example performs multiple write operations on the
292316``sample_restaurants.restaurants`` and ``sample_mflix.movies``
293317namespaces by using the ``bulk_write()`` method on a ``MongoClient``
294- instance:
295-
296- .. io-code-block::
297- :copyable:
298-
299- .. input:: /includes/write/bulk-write.py
300- :start-after: start-bulk-write-mixed-client
301- :end-before: end-bulk-write-mixed-client
302- :language: python
303-
304- .. output::
305- :visible: false
306-
307- ClientBulkWriteResult({'anySuccessful': True, 'error': None, 'writeErrors': [],
308- 'writeConcernErrors': [], 'nInserted': 1, 'nUpserted': 0, 'nMatched': 1,
309- 'nModified': 1, 'nDeleted': 344, 'insertResults': {}, 'updateResults': {},
310- 'deleteResults': {}}, acknowledged=True, verbose=False)
318+ instance. Select the :guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the
319+ corresponding code:
320+
321+ .. tabs::
322+
323+ .. tab:: Synchronous
324+ :tabid: sync
325+
326+ .. io-code-block::
327+ :copyable:
328+
329+ .. input:: /includes/write/bulk-write.py
330+ :start-after: start-bulk-write-mixed-client
331+ :end-before: end-bulk-write-mixed-client
332+ :language: python
333+
334+ .. output::
335+ :visible: false
336+
337+ ClientBulkWriteResult({'anySuccessful': True, 'error': None, 'writeErrors': [],
338+ 'writeConcernErrors': [], 'nInserted': 1, 'nUpserted': 0, 'nMatched': 1,
339+ 'nModified': 1, 'nDeleted': 344, 'insertResults': {}, 'updateResults': {},
340+ 'deleteResults': {}}, acknowledged=True, verbose=False)
341+
342+ .. tab:: Asynchronous
343+ :tabid: async
344+
345+ .. io-code-block::
346+ :copyable:
347+
348+ .. input:: /includes/write/bulk-write-async.py
349+ :start-after: start-bulk-write-mixed-client
350+ :end-before: end-bulk-write-mixed-client
351+ :language: python
352+
353+ .. output::
354+ :visible: false
355+
356+ ClientBulkWriteResult({'anySuccessful': True, 'error': None, 'writeErrors': [],
357+ 'writeConcernErrors': [], 'nInserted': 1, 'nUpserted': 0, 'nMatched': 1,
358+ 'nModified': 1, 'nDeleted': 344, 'insertResults': {}, 'updateResults': {},
359+ 'deleteResults': {}}, acknowledged=True, verbose=False)
311360
312361Customize Bulk Write Operations
313362-------------------------------
@@ -363,14 +412,29 @@ to the ``Collection.bulk_write()`` method:
363412
364413The following example calls the ``bulk_write()`` method from the preceding
365414:ref:`pymongo-bulk-write-collection-ex` but sets the ``ordered`` option
366- to ``False``:
415+ to ``False``. Select the :guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see
416+ the corresponding code:
367417
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:
418+ .. tabs::
419+
420+ .. tab:: Synchronous
421+ :tabid: sync
422+
423+ .. literalinclude:: /includes/write/bulk-write.py
424+ :start-after: start-bulk-write-unordered
425+ :end-before: end-bulk-write-unordered
426+ :language: python
427+ :copyable:
373428
429+ .. tab:: Asynchronous
430+ :tabid: async
431+
432+ .. literalinclude:: /includes/write/bulk-write-async.py
433+ :start-after: start-bulk-write-unordered
434+ :end-before: end-bulk-write-unordered
435+ :language: python
436+ :copyable:
437+
374438If any of the write operations in an unordered bulk write fail, {+driver-short+}
375439reports the errors only after attempting all operations.
376440
@@ -436,25 +500,53 @@ to the ``MongoClient.bulk_write()`` method:
436500
437501The following example calls the ``bulk_write()`` method from the preceding
438502:ref:`pymongo-bulk-write-client-ex` but sets the ``verbose_results`` option
439- to ``True``:
440-
441- .. io-code-block::
442- :copyable:
503+ to ``True``. Select the :guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see
504+ the corresponding code:
505+
506+ .. tabs::
507+
508+ .. tab:: Synchronous
509+ :tabid: sync
510+
511+ .. io-code-block::
512+ :copyable:
513+
514+ .. input:: /includes/write/bulk-write.py
515+ :start-after: start-bulk-write-verbose
516+ :end-before: end-bulk-write-verbose
517+ :language: python
518+
519+ .. output::
520+ :visible: false
521+
522+ ClientBulkWriteResult({'anySuccessful': True, 'error': None, 'writeErrors': [],
523+ 'writeConcernErrors': [], 'nInserted': 1, 'nUpserted': 0, 'nMatched': 1, 'nModified': 1,
524+ 'nDeleted': 344, 'insertResults': {0: InsertOneResult(ObjectId('...'),
525+ acknowledged=True)}, 'updateResults': {1: UpdateResult({'ok': 1.0, 'idx': 1, 'n': 1,
526+ 'nModified': 1}, acknowledged=True)}, 'deleteResults': {2: DeleteResult({'ok': 1.0,
527+ 'idx': 2, 'n': 344}, acknowledged=True)}}, acknowledged=True, verbose=True)
528+
529+ .. tab:: Asynchronous
530+ :tabid: async
531+
532+ .. io-code-block::
533+ :copyable:
534+
535+ .. input:: /includes/write/bulk-write-async.py
536+ :start-after: start-bulk-write-verbose
537+ :end-before: end-bulk-write-verbose
538+ :language: python
539+
540+ .. output::
541+ :visible: false
542+
543+ ClientBulkWriteResult({'anySuccessful': True, 'error': None, 'writeErrors': [],
544+ 'writeConcernErrors': [], 'nInserted': 1, 'nUpserted': 0, 'nMatched': 1, 'nModified': 1,
545+ 'nDeleted': 344, 'insertResults': {0: InsertOneResult(ObjectId('...'),
546+ acknowledged=True)}, 'updateResults': {1: UpdateResult({'ok': 1.0, 'idx': 1, 'n': 1,
547+ 'nModified': 1}, acknowledged=True)}, 'deleteResults': {2: DeleteResult({'ok': 1.0,
548+ 'idx': 2, 'n': 344}, acknowledged=True)}}, acknowledged=True, verbose=True)
443549
444- .. input:: /includes/write/bulk-write.py
445- :start-after: start-bulk-write-verbose
446- :end-before: end-bulk-write-verbose
447- :language: python
448-
449- .. output::
450- :visible: false
451-
452- ClientBulkWriteResult({'anySuccessful': True, 'error': None, 'writeErrors': [],
453- 'writeConcernErrors': [], 'nInserted': 1, 'nUpserted': 0, 'nMatched': 1, 'nModified': 1,
454- 'nDeleted': 344, 'insertResults': {0: InsertOneResult(ObjectId('...'),
455- acknowledged=True)}, 'updateResults': {1: UpdateResult({'ok': 1.0, 'idx': 1, 'n': 1,
456- 'nModified': 1}, acknowledged=True)}, 'deleteResults': {2: DeleteResult({'ok': 1.0,
457- 'idx': 2, 'n': 344}, acknowledged=True)}}, acknowledged=True, verbose=True)
458550
459551Return Values
460552-------------
0 commit comments