diff --git a/docs/changelog.rst b/docs/changelog.rst index 5baa761b..5c8f297f 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -5,6 +5,7 @@ Changelog Changes in dev ============== +- No longer always upsert on save for items with a '_id' - Error raised if update doesn't have an operation - DeReferencing is now thread safe - Errors raised if trying to perform a join in a query diff --git a/mongoengine/document.py b/mongoengine/document.py index 5ef93e35..68668a77 100644 --- a/mongoengine/document.py +++ b/mongoengine/document.py @@ -191,10 +191,11 @@ class Document(BaseDocument): actual_key = self._db_field_map.get(k, k) select_dict[actual_key] = doc[actual_key] + upsert = self._created if updates: - collection.update(select_dict, {"$set": updates}, upsert=True, safe=safe, **write_options) + collection.update(select_dict, {"$set": updates}, upsert=upsert, safe=safe, **write_options) if removals: - collection.update(select_dict, {"$unset": removals}, upsert=True, safe=safe, **write_options) + collection.update(select_dict, {"$unset": removals}, upsert=upsert, safe=safe, **write_options) cascade = self._meta.get('cascade', True) if cascade is None else cascade if cascade: @@ -219,6 +220,7 @@ class Document(BaseDocument): self[id_field] = self._fields[id_field].to_python(object_id) self._changed_fields = [] + self._created = False signals.post_save.send(self.__class__, document=self, created=created) def cascade_save(self, *args, **kwargs):