MCPcopy Index your code
hub / github.com/MongoEngine/mongoengine / update

Method update

mongoengine/document.py:646–663  ·  view source on GitHub ↗

Performs an update on the :class:`~mongoengine.Document` A convenience wrapper to :meth:`~mongoengine.QuerySet.update`. Raises :class:`OperationError` if called on an object that has not yet been saved.

(self, **kwargs)

Source from the content-addressed store, hash-verified

644 return select_dict
645
646 def update(self, **kwargs):
647 """Performs an update on the :class:`~mongoengine.Document`
648 A convenience wrapper to :meth:`~mongoengine.QuerySet.update`.
649
650 Raises :class:`OperationError` if called on an object that has not yet
651 been saved.
652 """
653 if self.pk is None:
654 if kwargs.get("upsert", False):
655 query = self.to_mongo()
656 if "_cls" in query:
657 del query["_cls"]
658 return self._qs.filter(**query).update_one(**kwargs)
659 else:
660 raise OperationError("attempt to update a document not yet saved")
661
662 # Need to add shard key to query, or you get an error
663 return self._qs.filter(**self._object_key).update_one(**kwargs)
664
665 def delete(self, signal_kwargs=None, **write_concern):
666 """Delete the :class:`~mongoengine.Document` from the database. This

Callers 15

_find_referencesMethod · 0.45
_get_connection_settingsFunction · 0.45
set_write_concernFunction · 0.45
set_read_write_concernFunction · 0.45
on_document_pre_saveMethod · 0.45
to_mongoMethod · 0.45
prepare_query_valueMethod · 0.45
sync_allMethod · 0.45
__copy__Method · 0.45
modifyMethod · 0.45
saveMethod · 0.45
create_indexMethod · 0.45

Calls 5

to_mongoMethod · 0.95
OperationErrorClass · 0.85
update_oneMethod · 0.80
getMethod · 0.45
filterMethod · 0.45