Update and return the updated document. Returns either the document before or after modification based on `new` parameter. If no documents match the query and `upsert` is false, returns ``None``. If upserting and `new` is false, returns ``None``. If the full_respons
(
self,
upsert=False,
full_response=False,
remove=False,
new=False,
array_filters=None,
**update,
)
| 669 | ) |
| 670 | |
| 671 | def modify( |
| 672 | self, |
| 673 | upsert=False, |
| 674 | full_response=False, |
| 675 | remove=False, |
| 676 | new=False, |
| 677 | array_filters=None, |
| 678 | **update, |
| 679 | ): |
| 680 | """Update and return the updated document. |
| 681 | |
| 682 | Returns either the document before or after modification based on `new` |
| 683 | parameter. If no documents match the query and `upsert` is false, |
| 684 | returns ``None``. If upserting and `new` is false, returns ``None``. |
| 685 | |
| 686 | If the full_response parameter is ``True``, the return value will be |
| 687 | the entire response object from the server, including the 'ok' and |
| 688 | 'lastErrorObject' fields, rather than just the modified document. |
| 689 | This is useful mainly because the 'lastErrorObject' document holds |
| 690 | information about the command's execution. |
| 691 | |
| 692 | :param upsert: insert if document doesn't exist (default ``False``) |
| 693 | :param full_response: return the entire response object from the |
| 694 | server (default ``False``, not available for PyMongo 3+) |
| 695 | :param remove: remove rather than updating (default ``False``) |
| 696 | :param new: return updated rather than original document |
| 697 | (default ``False``) |
| 698 | :param array_filters: A list of filters specifying which array elements an update should apply. |
| 699 | :param update: Django-style update keyword arguments |
| 700 | """ |
| 701 | |
| 702 | if remove and new: |
| 703 | raise OperationError("Conflicting parameters: remove and new") |
| 704 | |
| 705 | if not update and not upsert and not remove: |
| 706 | raise OperationError("No update parameters, must either update or remove") |
| 707 | |
| 708 | if self._none or self._empty: |
| 709 | return None |
| 710 | |
| 711 | queryset = self.clone() |
| 712 | query = queryset._query |
| 713 | if not remove: |
| 714 | update = transform.update(queryset._document, **update) |
| 715 | sort = queryset._ordering |
| 716 | |
| 717 | try: |
| 718 | if full_response: |
| 719 | msg = "With PyMongo 3+, it is not possible anymore to get the full response." |
| 720 | warnings.warn(msg, DeprecationWarning) |
| 721 | if remove: |
| 722 | result = queryset._collection.find_one_and_delete( |
| 723 | query, sort=sort, **self._cursor_args |
| 724 | ) |
| 725 | else: |
| 726 | if new: |
| 727 | return_doc = ReturnDocument.AFTER |
| 728 | else: |
nothing calls this directly
no test coverage detected