@@ -266,7 +266,8 @@ Collection Bulk Write Example
266
266
267
267
The following example performs multiple write operations on the
268
268
``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:
270
271
271
272
.. io-code-block::
272
273
:copyable:
@@ -291,7 +292,8 @@ Client Bulk Write Example
291
292
The following example performs multiple write operations on the
292
293
``sample_restaurants.restaurants`` and ``sample_mflix.movies``
293
294
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:
295
297
296
298
.. io-code-block::
297
299
:copyable:
@@ -363,14 +365,29 @@ to the ``Collection.bulk_write()`` method:
363
365
364
366
The following example calls the ``bulk_write()`` method from the preceding
365
367
: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:
367
370
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
373
375
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
+
374
391
If any of the write operations in an unordered bulk write fail, {+driver-short+}
375
392
reports the errors only after attempting all operations.
376
393
@@ -436,7 +453,8 @@ to the ``MongoClient.bulk_write()`` method:
436
453
437
454
The following example calls the ``bulk_write()`` method from the preceding
438
455
: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:
440
458
441
459
.. io-code-block::
442
460
:copyable:
@@ -456,6 +474,51 @@ to ``True``:
456
474
'nModified': 1}, acknowledged=True)}, 'deleteResults': {2: DeleteResult({'ok': 1.0,
457
475
'idx': 2, 'n': 344}, acknowledged=True)}}, acknowledged=True, verbose=True)
458
476
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
+
459
522
Return Values
460
523
-------------
461
524
0 commit comments