diff --git a/mongoengine/queryset.py b/mongoengine/queryset.py index 8c13dc93..5c329781 100644 --- a/mongoengine/queryset.py +++ b/mongoengine/queryset.py @@ -588,7 +588,7 @@ class QuerySet(object): return mongo_update - def update(self, safe_update=True, **update): + def update(self, safe_update=True, upsert=False, **update): """Perform an atomic update on the fields matched by the query. :param safe: check if the operation succeeded before returning @@ -602,14 +602,14 @@ class QuerySet(object): update = QuerySet._transform_update(self._document, **update) try: self._collection.update(self._query, update, safe=safe_update, - multi=True) + upsert=upsert, multi=True) except pymongo.errors.OperationFailure, err: if unicode(err) == u'multi not coded yet': message = u'update() method requires MongoDB 1.1.3+' raise OperationError(message) raise OperationError(u'Update failed (%s)' % unicode(err)) - def update_one(self, safe_update=True, **update): + def update_one(self, safe_update=True, upsert=False, **update): """Perform an atomic update on first field matched by the query. :param safe: check if the operation succeeded before returning @@ -623,7 +623,7 @@ class QuerySet(object): # as the default may change to 'True' if pymongo.version >= '1.1.1': self._collection.update(self._query, update, safe=safe_update, - multi=False) + upsert=upsert, multi=False) else: # Older versions of PyMongo don't support 'multi' self._collection.update(self._query, update, safe=safe_update)