Represents an update_one operation.
| 553 | |
| 554 | |
| 555 | class UpdateOne(_UpdateOp): |
| 556 | """Represents an update_one operation.""" |
| 557 | |
| 558 | __slots__ = () |
| 559 | |
| 560 | def __init__( |
| 561 | self, |
| 562 | filter: Mapping[str, Any], |
| 563 | update: Union[Mapping[str, Any], _Pipeline], |
| 564 | upsert: Optional[bool] = None, |
| 565 | collation: Optional[_CollationIn] = None, |
| 566 | array_filters: Optional[list[Mapping[str, Any]]] = None, |
| 567 | hint: Optional[_IndexKeyHint] = None, |
| 568 | namespace: Optional[str] = None, |
| 569 | sort: Optional[Mapping[str, Any]] = None, |
| 570 | ) -> None: |
| 571 | """Represents an update_one operation. |
| 572 | |
| 573 | For use with :meth:`~pymongo.asynchronous.collection.AsyncCollection.bulk_write`, :meth:`~pymongo.collection.Collection.bulk_write`, |
| 574 | :meth:`~pymongo.asynchronous.mongo_client.AsyncMongoClient.bulk_write` and :meth:`~pymongo.mongo_client.MongoClient.bulk_write`. |
| 575 | |
| 576 | :param filter: A query that matches the document to update. |
| 577 | :param update: The modifications to apply. |
| 578 | :param upsert: If ``True``, perform an insert if no documents |
| 579 | match the filter. |
| 580 | :param collation: An instance of |
| 581 | :class:`~pymongo.collation.Collation`. |
| 582 | :param array_filters: A list of filters specifying which |
| 583 | array elements an update should apply. |
| 584 | :param hint: An index to use to support the query |
| 585 | predicate specified either by its string name, or in the same |
| 586 | format as passed to |
| 587 | :meth:`~pymongo.asynchronous.collection.AsyncCollection.create_index` or :meth:`~pymongo.collection.Collection.create_index` (e.g. |
| 588 | ``[('field', ASCENDING)]``). This option is only supported on |
| 589 | MongoDB 4.2 and above. |
| 590 | :param namespace: The namespace in which to update a document. |
| 591 | :param sort: Specify which document the operation updates if the query matches |
| 592 | multiple documents. The first document matched by the sort order will be updated. |
| 593 | |
| 594 | .. versionchanged:: 4.10 |
| 595 | Added ``sort`` option. |
| 596 | .. versionchanged:: 4.9 |
| 597 | Added the `namespace` option to support `MongoClient.bulk_write`. |
| 598 | .. versionchanged:: 3.11 |
| 599 | Added the `hint` option. |
| 600 | .. versionchanged:: 3.9 |
| 601 | Added the ability to accept a pipeline as the `update`. |
| 602 | .. versionchanged:: 3.6 |
| 603 | Added the `array_filters` option. |
| 604 | .. versionchanged:: 3.5 |
| 605 | Added the `collation` option. |
| 606 | """ |
| 607 | super().__init__(filter, update, upsert, collation, array_filters, hint, namespace, sort) |
| 608 | |
| 609 | def _add_to_bulk(self, bulkobj: _AgnosticBulk) -> None: |
| 610 | """Add this operation to the _AsyncBulk/_Bulk instance `bulkobj`.""" |
| 611 | bulkobj.add_update( |
| 612 | self._filter, |
no outgoing calls