Represents an update_many operation.
| 639 | |
| 640 | |
| 641 | class UpdateMany(_UpdateOp): |
| 642 | """Represents an update_many operation.""" |
| 643 | |
| 644 | __slots__ = () |
| 645 | |
| 646 | def __init__( |
| 647 | self, |
| 648 | filter: Mapping[str, Any], |
| 649 | update: Union[Mapping[str, Any], _Pipeline], |
| 650 | upsert: Optional[bool] = None, |
| 651 | collation: Optional[_CollationIn] = None, |
| 652 | array_filters: Optional[list[Mapping[str, Any]]] = None, |
| 653 | hint: Optional[_IndexKeyHint] = None, |
| 654 | namespace: Optional[str] = None, |
| 655 | ) -> None: |
| 656 | """Create an UpdateMany instance. |
| 657 | |
| 658 | For use with :meth:`~pymongo.asynchronous.collection.AsyncCollection.bulk_write`, :meth:`~pymongo.collection.Collection.bulk_write`, |
| 659 | :meth:`~pymongo.asynchronous.mongo_client.AsyncMongoClient.bulk_write` and :meth:`~pymongo.mongo_client.MongoClient.bulk_write`. |
| 660 | |
| 661 | :param filter: A query that matches the documents to update. |
| 662 | :param update: The modifications to apply. |
| 663 | :param upsert: If ``True``, perform an insert if no documents |
| 664 | match the filter. |
| 665 | :param collation: An instance of |
| 666 | :class:`~pymongo.collation.Collation`. |
| 667 | :param array_filters: A list of filters specifying which |
| 668 | array elements an update should apply. |
| 669 | :param hint: An index to use to support the query |
| 670 | predicate specified either by its string name, or in the same |
| 671 | format as passed to |
| 672 | :meth:`~pymongo.asynchronous.collection.AsyncCollection.create_index` or :meth:`~pymongo.collection.Collection.create_index` (e.g. |
| 673 | ``[('field', ASCENDING)]``). This option is only supported on |
| 674 | MongoDB 4.2 and above. |
| 675 | :param namespace: (optional) The namespace in which to update documents. |
| 676 | |
| 677 | .. versionchanged:: 4.9 |
| 678 | Added the `namespace` option to support `MongoClient.bulk_write`. |
| 679 | .. versionchanged:: 3.11 |
| 680 | Added the `hint` option. |
| 681 | .. versionchanged:: 3.9 |
| 682 | Added the ability to accept a pipeline as the `update`. |
| 683 | .. versionchanged:: 3.6 |
| 684 | Added the `array_filters` option. |
| 685 | .. versionchanged:: 3.5 |
| 686 | Added the `collation` option. |
| 687 | """ |
| 688 | super().__init__(filter, update, upsert, collation, array_filters, hint, namespace, None) |
| 689 | |
| 690 | def _add_to_bulk(self, bulkobj: _AgnosticBulk) -> None: |
| 691 | """Add this operation to the _AsyncBulk/_Bulk instance `bulkobj`.""" |
| 692 | bulkobj.add_update( |
| 693 | self._filter, |
| 694 | self._doc, |
| 695 | True, |
| 696 | self._upsert, |
| 697 | collation=validate_collation_or_none(self._collation), |
| 698 | array_filters=self._array_filters, |
no outgoing calls